TITLE: Sums of squares question
QUESTION [5 upvotes]: If you have $a,b\in\mathbb{N}$ such that $a^2+b^2=M$, are there other natural numbers $c,d$ such that $c^2+d^2=M$? If so, is there an algorithm for generating such pairs or an equation relating them to $a$ and $b$? I tried messing around with a few ideas using $\mathbb{Z[i]}$, but didn't really get anywhere.

REPLY [2 votes]: The others have nicely answered your question. But there is something else worth saying. According to a theorem of Jacobi, the number of solutions to $x^2+y^2=M$ in integers is equal to eight times the number of odd divisors of $M$ which are $1$ mod $4$ minus eight times the number of odd divisors of $M$ which are $3$ mod $4$. One recovers as a particular case Fermat's theorem on sums of two squares.
This theorem follows from the fact that the Dedekind zeta function of $\mathbf Q[i]$ equals $\zeta(s)L(\chi,s)$, where $\chi$ is the primitive quadratic character of conductor $4$.
(The reason for the factor $8$ is that solutions generally occur in "octopules": $(x,y),(y,x),(-x,y),(x,-y),...$).