To prove the necessity: Since p is a prime, if the indeterminate equation (1) has a solution x0,y0, it must satisfy
(x0,y0)=(x0y0,p)=1,
Thus, there must be a y0−1 such that y0−1y0≡1(modp). This leads to
(x0y0−1)2+1+kp=(y0−1)2p
If p>2, from the above equation we get
(x0y0−1)2≡−1(modp)
That is, (p−1)=1, which implies p=4k+1 (see Chapter 4, §5, Corollary 3). This proves the necessity.
To prove the sufficiency: When p=2, we have 2=12+12, so (1) has a solution. When p>2, from (p−1)=1 (i.e., p=4k+1), there must be an x such that
x2+1≡0(modp),0⩽x<p
Let m0 be the smallest m for which
x2+y2=mp
holds. If we can prove m0=1, then we have proven the sufficiency. At this point, similar to the proof of Theorem 2 in §1, we can show that (x,y)=1 (left to the reader). We will use proof by contradiction to show that m0=1. If m0>1, take
{u≡x(modm0),v≡y(modm0),∣u∣⩽m0/2,∣v∣⩽m0/2
From this and (x,y)=1, we immediately get
0<u2+v2⩽m02/2,u2+v2≡x2+y2(modm0)
Using equation (3) with m=m0, we get
(u2+v2)(x2+y2)=m1m02p,1⩽m1<m0.
Using the well-known identity
(a12+a22)(b12+b22)=(a1b1+a2b2)2+(a1b2−a2b1)2,
the above equation becomes
(ux+vy)2+(uy−wx)2=m1m02p.
From equation (4) and equation (3) with m=m0, we have
ux+vy≡x2+y2≡0(modm0)uy−vx≡0(modm0)
Thus, we have
(m0ux+vy)2+(m0uy−vx)2=m1p,1⩽m1<m0
This contradicts the minimality of m0. Therefore, m0=1. Proof complete.