import java.util.*;
import java.lang.*;
import java.io.*;
// https://[Log in to view URL]
class Main {
public static void main(String[] args) {
var x = 423;
var y = 56328;
var z = cantorPair(x, y);
System.out.println(String.format("x=%s, y=%s", x, y));
System.out.println("z=" + z);
System.out.println(Arrays.toString(cantorUnpair(z)));
}
public static long cantorPair(int a, int b) {
return (long) (0.5 * (a + b) * (a + b + 1) + b);
}
public static int[] cantorUnpair(long z) {
var t = (int) Math.floor((Math.sqrt(8 * z + 1) - 1) / 2);
var x = (long) t * (t + 3) / 2 - z;
var y = z - (long) t * (t + 1) / 2;
return new int[]{(int) x, (int) y};
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: