Prove that every prime $p$ of which $-1$ is a quadratic residue can be represented in the form $x^2+y^2$.
In a similar question the result is achieved by noting that every prime of the form $p=4k+1$ can be written as the sum of two squares and "it follows that -1 is a quadratic residue $\pmod p$ ". So, in my question, does it just suffice to show that $p$ is the sum of two squares if $p \equiv 1 \pmod 4$? How should we proceed?
Suppose $n^2+1 = mp$. In the plane, mark all points of the form $(a,an)\pmod p$ It forms a regular grid of points. This grid repeats with offset $(p,0)$ and $(0,p)$, and there are $p$ points in any $p\times p$ square.
The distance between any two of these points is $d=\sqrt{(a-b)^2+(an-bn-cp)^2}$. The expression under the square-root is $(n^2+1)(a-b)^2 - 2cp(an-bn) + c^2p^2$ which is a multiple of $p$. So the possible distances are $\sqrt{p},\sqrt{2p},\sqrt{3p},...$
If the smallest of these distances is $\sqrt{p}$, then $(a-b)^2 + (an-bn-cp)^2=p$, and $p$ is the sum of two squares.
If not, then the distance between any two points is at least $\sqrt{2p}$. So there is a circle of radius $\sqrt{p/2}$ around each point, and they don't intersect. The total area of $p$ of these circles is $p\pi(p/2)>p^2$. But $p$ of the circles fit in a $p\times p$ square. This is a contradiction, so the closest points are $\sqrt{p}$ apart, and $p$ is the sum of two squares.