Number Theory: sum of two squares If $p$ is a prime and $p \equiv 1 \bmod 4$, how many ways are there to write $p$ as a sum of two squares? Is there an explicit formulation for this?
There's a theorem that says that $p = 1 \bmod 4$ if and only if $p$ is a sum of two squares so this number must be at least 1. There's also the Sum of Two Squares Theorem for the prime factorization of integers and the Pythagorean Hypotenuse Proposition which says that a number $c$ is a hypotenuse if and only if it's a factor of $1 \bmod 4$ primes. All of these theorems only assert the existence of $1 \bmod 4$ primes as the sum of two squares. How do I (perhaps use these altogether) to find the exact number of different ways to write such prime as a sum of two squares?
 A: If $p$ is prime $p \equiv 1 \bmod \ 4 $ then $\exists!(a, b), (b, a) \in \mathbb N^2 $ such that $p = a^2 + b^2$. In fact, suppose $p = a^2 + b^2 = c^2 + d^2$ then in $\mathbb Z[i]$ $(a + ib)(a - ib) = (c + id)(c - id)$ but $N(a + ib) = N(a - ib) = N(c + id) = N(c - id) = p$ where $N(a + ib) = a^2 + b^2$ is the norm in $\mathbb Z[i]$. Then we have that $a + ib, a - ib, c + id, c - id$ are primes in $\mathbb Z[i]$ therefore we can  conclude that  $a = b, c = d$.
A: If $n$ has two distinct expressions as a sum of two squares, $n=a^2+b^2=c^2+d^2$, then $n$ divides $(ac+bd)(ac-bd)$. But then you can show $n$ doesn't divide either $ac+bd$ or $ac-bd$ (it's a bit tricky), from which it follows that $n$ isn't prime. 
Then the contrapositive is that if $n$ is prime it doesn't have more than one representation as a sum of two squares. 
A: Here is a reference that gives an explicit formula for your problem, even extending to all integers (instead of just primes) http://mathworld.wolfram.com/SumofSquaresFunction.html
