The Logic for this formula is very simple . Let (y+x) indicate the layer this coordinate lies…(1 + (y+x)) * (y+x) / 2 is the arithmetic progression formula . finally add the value with x to complete the mapping.

Remember that since x,y <= 200.000, 200.000 * 200.000 can be bigger than 32-bit int, use long long instead.