To prove the necessity, we need to show that 4∤n and n has no prime factors of the form 4k+3. In this case, we must have (x,y)=(x,n)=(y,n)=1. If 4∣n, then we have
x2+y2≡0(mod4)
This is impossible when (x,2)=(y,2)=1. Therefore, we must have 4∤n. If there exists a prime p≡3(mod4) such that p∣n, then we have (p,x)=(p,y)=1 and
x2+y2≡0(modp)
Following the proof of the necessity in Theorem 2, we can deduce that p≡1(mod4), which is a contradiction.
For sufficiency, 1=12+02 and 2=12+12, so the conclusion is obviously true. We will use induction to prove that when n=pα and p≡1(mod4),
x2+y2=pα,(x,y)=1
has a solution. When α=1, this is Theorem 1, so there is a solution. Assume the conclusion holds for α=k. We will prove that the conclusion also holds for α=k+1. Suppose
x12+y12=p,xk2+yk2=pk,(x1,y1)=1(xk,yk)=1.
From this and equation (5), we have
(x1xk+y1yk)2+(x1yk−y1xk)2=pk+1(x1xk−y1yk)2+(x1yk+y1xk)2=pk+1
At this point,
d1=(x1xk+y1yk,x1yk−y1xk)=1
or
d2=(x1xk−y1yk,x1yk+y1xk)=1
at least one of them holds. If not, d1>1 and d2>1, then from equations (10) and (11), we know p∣d1 and p∣d2. Therefore, p∣2x1xk, so at least one of p∣x1 or p∣xk must hold, but from equations (8) and (9), this is impossible. Therefore, when d1=1, from equation (10), the conclusion holds for α=k+1. When d2=1, from equation (11), the conclusion holds for α=k+1. This proves that for any α≥1, the indeterminate equation (7) always has a solution.
Next, we prove that if (n1,n2)=1 and
x12+y12=n1,x22+y22=n2,(x1,y1)=1(x2,y2)=1
then when n=n1n2, the indeterminate equation (6) must have a solution satisfying (x,y)=1. From equation (5), we have
(x1x2+y1y2)2+(x1y2−y1x2)2=n1n2
If d=(x1x2+y1y2,x1y2−y1x2)>1, then there must be a prime q∣d. Therefore,
x1x2≡−y1y2(modq),x1y2≡y1x2(modq)
At this point, q∤x1. Otherwise, if q∣x1, from the above two equations, we get q∣y1y2 and q∣y1x2. From (x1,y1)=1, we deduce q∣y2 and q∣x2, which contradicts (x2,y2)=1. Similarly, we can prove that q cannot divide y1, x2, or y2. From equations (15) and (16), we easily get
x1(x22+y22)≡0(modq),x2(x12+y12)≡0(modq)
From this and q∤x1x2, we get (note: q is a prime)
x12+y12≡x22+y22≡0(modq)
From this and equations (12) and (13), we get n1≡n2≡0(modq), which contradicts (n1,n2)=1. Therefore, d=1. From this and equation (14), we have proven the desired conclusion.
Combining all the above discussions, we have proven the sufficiency. Proof complete.