<s>[INST] Representing a given number as the sum of two squares. 
There are four essentially different representations of $1885$ as the sum of squares of two positive integers. Find all of them.

I am guessing the must be some nice way of solving $z= x^2 + y^2 $  where x and y are integers in general that i don't know.  
Is there some general way to know how many solution exists or bound it without computing it?
 [/INST] Since $\mathbb{Z}[i]$ is a UFD, by letting
$$ r_2(n)=\left|\left\{(a,b)\in\mathbb{Z}^2:a^2+b^2=n\right\}\right|$$
we have 
$$ r_2(n) = 4(\chi_4*1)(n) = 4\sum_{d\mid n}\chi_4(d) $$
where $\chi_4(m)$ equals $1$ if $m\equiv 1\pmod{4}$, $-1$ if $m\equiv 3\pmod{4}$ and zero otherwise.
This is essentially due to the Brahmagupta-Fibonacci identity
$$ (a^2+b^2)(c^2+d^2) = (ad-bc)^2+(ac+bd)^2 $$
equivalent to the multiplicativity of the norm over $\mathbb{Z}[i]$.
Since $1885=5\cdot 13\cdot 29$ and $5=1^2+2^2$, $13=2^2+3^2$, $29=2^2+5^2$, from
$$(1+2i)(2+3i)(2+5i)=-43-6i$$
$$(1-2i)(2+3i)(2+5i)=21+38i$$
$$(1+2i)(2-3i)(2+5i)=11+42i$$
$$(1+2i)(2+3i)(2-5i)=27+34i$$
we get that the wanted representations are
$$ 1885=6^2+43^2 = 21^2+38^2 = 11^2+42^2=27^2+34^2.$$
</s>