What are the numbers that can be uniquely represented as the sum of two squares? I know that primes of the form $4k+1$ can be represented uniquely as the sum of two squares (not counting order or negative numbers). But there are others like $8$ and $9$ that are not "prime and of the form $4k+1$" that can also be represented uniquely.
Is there a general pattern?
 A: The page on mathworld gives the following:
For $n = 2^a\left(\prod_{p_i\equiv 1\mod 4} p_i^{e_i}\right)\left(\prod_{q_j\equiv 3\mod 4} q_j^{f_j}\right)$, define $B = \prod e_i + 1$, and we have
$$r_2'(n) = \begin{cases} 0 &\text{if any }f_j\text{ is odd} \\ \frac{1}{2}B &\text{if }B\text{ is even} \\ \frac{1}{2}(B - (-1)^a) &\text{if }B\text{ is odd} \end{cases}$$
Therefore, assuming all $f_j$ are even, there are three cases:

*

*If $B$ is even, then $B = 2$, meaning there is exactly one $e_1 = 1$, and

$$n = 2^k p \left(\prod_{q_j\equiv 3\mod 4} q_j^{f_j}\right)^2$$

*

*Otherwise, either $B = 3$, $a$ is even, i.e.

$$n = 2^{2k} p^2 \left(\prod_{q_j\equiv 3\mod 4} q_j^{f_j}\right)^2$$

*

*Or, $B = 1$, $a$ is odd, i.e.

$$n = 2^{2k + 1} \left(\prod_{q_j\equiv 3\mod 4} q_j^{f_j}\right)^2$$
Note: The formula seems to be wrong for square values.
A: COMMENT.-The general solution of the diophantine equation $$x^2+y^2=z^2+w^2$$ is given by the identity $$(aX+bY)^2+(aY-bX)^2=(aX-bY)^2+(aY+bX)^2$$ where $a,b$ are arbitrary integers and $X,Y$ are two parameters.
You can verify that both sides give $(a^2+b^2)(X^2+Y^2)$.
What you can try is to find conditions to have $x=z$ or $x=w$ so the corresponding integer numbers have unique representation as sum of squares.
