Given the function $f: \mathbb{Z}^+ \times \mathbb{Z}^+ \to \mathbb{Z}^+$
$f(a,b) = b^2 +a$, if $b>a$
or $a^2 +a + b$, if $b<a$,
which associates $a,b \to z$, find its inverse, which associates $z \to a, b$.
Given the function $f: \mathbb{Z}^+ \times \mathbb{Z}^+ \to \mathbb{Z}^+$
$f(a,b) = b^2 +a$, if $b>a$
or $a^2 +a + b$, if $b<a$,
which associates $a,b \to z$, find its inverse, which associates $z \to a, b$.
If you look back at the origin of the problem, this function is a bijection from $\mathbb N \times \mathbb N$ to $\mathbb N$.
To find the inverse, start by finding a $k$ so that $k^2 \leq z < (k+1)^2$.
Than see what happens depending if $z-k^2$ is larger or smaller than $k$.
The insignt here is that, if $x < y$ then $$(y-1)^2 + (y-1) + x < y^2 < y^2 + x < y^2 + y + x < (y+1)^2$$
Sombeody calculates $f(a,b) = c$, and you are only given c. You find the bigger of the two numbers by calculating $d = \left\lfloor \sqrt{c}\right\rfloor$. Then calculate $e = c - d^2$. If $e < d$, then we are in the $a < b$ case and $(a,b) = (e, d)$. If $e > d$ then we are in the $b < a$ case, and $(a,b) = (d, e - d)$