TITLE: Number Theory: sum of two squares
QUESTION [5 upvotes]: 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?

REPLY [2 votes]: 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.