This question is related to Efficiently finding two squares which sum to a prime.
The following 3 methods are found in Chapter 5.3 of The Higher Arithmetic by H. Davenport. However, I failed to construct a proof (or outline) for the correctness.
Gauss Construction
Given a prime $p=4k+1$, then let $$x\equiv\frac{(2k)!}{2(k!)^2}\mod p, |x|<\frac{p}{2}$$ $$y\equiv x\cdot(2k)!\mod p, |y|<\frac{p}{2}$$ there is $p=x^2+y^2$ shown by Gauss.
There are actually several questions about this proof for reference:
Gauss formulas to decompose a prime in the sum of two squares
Reference for a Post about Gauss formula for primes written as sum of two squares?
However, both answers only shows that $x^2+y^2\equiv0\mod p$ but cannot bound $x^2+y^2<\frac{p^2}{2}$ to actually be $p$. In fact, the proof works for any $|x|<\frac{p}{2}$ as long as letting $y\equiv x\cdot(2k)!$.
To continue tighten the bound, one can attempt to show that $0<|x|,|y|<\sqrt{p}$, which is a better bound and directly gives $0<x^2+y^2<2p$ and the desired equality.
Another way is to show that $x^2+y^2\equiv p\mod p^a$. By modding a power of $p$, since $\frac{p^2}{2}<p^a$, it is safe to say that $x^2+y^2=p$.
Serret Construction (Solved)
Find $0<h<\frac{p}{2}$ that $h^2+1\equiv 0\mod p$, then the continued fraction of $\frac{p}{h}$ can be proven to be symmetric and having even length. $$\frac{p}{h}=[q_0;q_1,...,q_m,q_m,...,q_1,q_0]$$ Then let $x$ be numerator of $[q_0;q_1,...,q_m]$ and $y$ be numerator of $[q_0;q_1,...,q_{m-1}]$, then $x^2+y^2=p$.
Jacobsthal Construction
Define $S(a)$ to be $$S(a)=\sum_n\left(\frac{n(n^2-a)}{p}\right)$$ using the Legendre symbol summing over all $n$ in the congruent class of $p$.
For any quadratic residue $R$ of $p$, let $x=\frac{|S(R)|}{2}$; for any non-quadratic residue $N$ of $p$, let $y=\frac{|S(N)|}{2}$, then there is $x^2+y^2=p$. It is claimed that the value of $|S(R)|$ and $|S(N)|$ are the only two possible values for $|S(a)|$.
It is told that this can be smartly proven from the following relationship: $$\sum_n\left(\frac{n(n+1)}{p}\right)=1$$ But the product $n(n^2-a)$ cannot be handled in a similar manner.
I am looking forward to a proof of correctness, or a link to the proof for construction, which I am unable to find on the web. Thank you.
\left
and\right
. – joriki Jan 12 '23 at 07:40