Elaborating the Condition in Fermat’s Two Square Theorem

Abstract

It is a well-known result that prime numbers congruent to 1 modulo 4 are representable as a sum of two squares. A recent article shows that the number of representations can imply the primality of square-free integers congruent to 1 modulo 4. However, the authors did not clarify the distinctness of the construction of representations in the proof of the main theorem. We provide a complementary proof to clarify this construction and also present an alternative proof based on Jacobi’s two square theorem.

Share and Cite:

Lin, N.R. (2026) Elaborating the Condition in Fermat’s Two Square Theorem. <i>Advances in Pure Mathematics</i>, <b>16</b>, 678-681. doi: <a href='https://doi.org/10.4236/apm.2026.169033' target='_blank' onclick='SetNum(154008)'>10.4236/apm.2026.169033</a>.

1. Introduction

Fermat’s two square theorem states that an odd prime p can be represented as a sum of two squares if and only if p1 (mod 4) [1]. However, this classical theorem only reveals the property of representability as a sum of two squares for primes congruent to 1 modulo 4, while little attention has been paid to the complete picture: using the number of such representations to detect primality for a general positive integer congruent to 1 modulo 4.

The recent article [2] presents a criterion for testing the primality of square-free positive integers congruent to 1 modulo 4, based on the uniqueness of representations as a sum of two squares. It goes beyond Fermat’s theorem and establishes a two-way connection between uniqueness of representation as a sum of two squares and primality. Modern primality tests include the deterministic, polynomial-time AKS algorithm [3] and the probabilistic Miller-Rabin test [4] [5], whose error probability can be reduced through repeated rounds. Unlike these computational algorithms, the theorem in [2] connects primality to the uniqueness of representation as a sum of two squares.

Unfortunately, the proof of the main theorem relies on the implicit assumption that the constructed representations are pairwise distinct, but a justification was not provided.

In this paper, we further clarify the counting step in the proof of the main theorem in [2], showing that the representations generated in Step 2 of Section 3 are pairwise distinct up to order and signs.

2. Two Supplementary Proofs of the Theorem

We first recall the main theorem of [2].

Two integer pairs are regarded as equivalent if one can be obtained from the other by changing order and signs independently. The representation of an integer a as a sum of two squares is considered unique if all integer solutions of a= c 2 + d 2 form exactly one equivalence class under this relation.

Theorem Let a be a square-free positive integer larger than 1 and a1 (mod 4). If a= c 2 + d 2 has a unique representation as a sum of two squares for a pair of integers c and d , then a is prime.

The authors of [2] prove the theorem by offering the following method to construct 2 k1 candidate representations as a sum of two squares for a= p 1 p 2 p k . Since such a representation exists, every prime factor congruent to 3 modulo 4 must occur with an even exponent. Combined with the fact that a is square-free, p j ’s are all distinct primes congruent to 1 modulo 4.

The first factor p 1 has a representation p 1 = x 1 2 + y 1 2 by Fermat’s two square theorem.

Assume that p j has a representation p j = x j 2 + y j 2 , where x j , y j >0 , and a representation A 2 + B 2 of p 1 p j1 has already been obtained. The Brahmagupta-Fibonacci Identity gives two representations for p 1 p j :

( A 2 + B 2 )( x j 2 + y j 2 )= ( A x j B y j ) 2 + ( A y j +B x j ) 2 = ( A x j +B y j ) 2 + ( A y j B x j ) 2 .

After incorporating all k factors, this process generates 2 k1 candidate representations.

In [2], these 2 k1 candidate representations are regarded as pairwise distinct up to order and signs in the proof of the main theorem, but this does not immediately follow. We now provide two ways to justify this counting step.

The first is to justify that the candidate representations are pairwise distinct up to order and signs by the following lemma.

Lemma The 2 k1 candidate representations as a sum of two squares are pairwise distinct, where we consider two representations the same if they differ only in the order of the summands or in signs.

Proof:

We prove the lemma by induction. The first prime factor p 1 has a unique representation class by Fermat’s Theorem. Suppose that p 1 p j1 has 2 j2 distinct representation classes ( A,B ) . Using the construction in [2], we obtain 2 j1 representations of p 1 p j1 p j =( A 2 + B 2 )( x j 2 + y j 2 ) . We show that each of these 2 j1 representations ( s,t ) is generated uniquely from a pair ( A,B ) along with one of the two Brahmagupta-Fibonacci identities.

Any representation ( A,B ) of p 1 p j1 that generates representation ( s,t ) of p 1 p j must satisfy

s=A y j +B x j , t=| A x j B y j |

or

s=| A y j B x j |, t=A x j +B y j .

By solving four linear systems arising from the sign choices in the absolute values, we obtain the following two possible solutions of ( A,B ) (the remaining two candidates have non-positive components and are discarded):

( A,B )=( y j s+ x j t p j , | x j s y j t | p j ),( | y j s x j t | p j , x j s+ y j t p j ).

If both of the solutions for A and B are feasible, then p j divides both s and t . Hence p j 2 divides s 2 + t 2 = p 1 p j1 p j , which forces p j to divide p 1 p j1 , contradicting that the prime factors p 1 , p 2 ,, p j are distinct. Therefore, ( s,t ) is generated in exactly one way. Hence each induction step doubles the number of distinct representation classes. This proves the lemma. ■

The lemma justifies the distinctness, up to order and signs, of the representations generated by the iterative construction in [2]. Therefore, at least 2 k1 representations are found by this construction. From this, unique representation as a sum of two squares leads to primality.

Another direct way is to prove the main theorem of [2] without the construction. In fact, we can get the number of representations from Jacobi’s two square theorem [6] [7]. Jacobi’s theorem states that the number of integer solutions ( x,y ) 2 of a= x 2 + y 2 is 4( d 1 ( a ) d 3 ( a ) ) , where d 1 ( a ) and d 3 ( a ) denote the numbers of positive divisors of a congruent to 1 and 3 (mod 4) respectively. As demonstrated in Step 1 of [2], the integer a= p 1 p 2 p k in the main theorem has only distinct prime factors congruent to 1 modulo 4. Therefore, the number of such solutions is

4( d 1 ( a ) d 3 ( a ) )=4×( 2 k 0 )= 2 k+2 .

On the other hand, if the representation of a as a sum of two squares is unique, then it has exactly eight integer solutions ( x,y ) , since neither coordinate can be zero when a is square-free, and their absolute values cannot be equal when a is odd. Thus, 2 k+2 =8 leads to k=1 . This proves the theorem.

3. Conclusion

We justify that the representations constructed in the proof of [2] are pairwise distinct, and we also provide an alternative proof based on Jacobi’s two square theorem. The main contribution of [2], together with the supplementary proofs presented in this paper, is to extend the scope of Fermat’s two square theorem by developing the representability of integers as sums of two squares from a property of primes into a criterion for primality testing.

Acknowledgements

The author thanks Way Kuo for insightful discussions. This research is supported by City University of Hong Kong project No. 9610556.

Conflicts of Interest

The author declares no conflicts of interest regarding the publication of this paper.

References

[1] Zagier, D. (1990) A One-Sentence Proof That Every Prime (mod 4) Is a Sum of Two Squares. The American Mathematical Monthly, 97, 144.[CrossRef]
[2] Li, H.-L., Fang, S.-C. and Kuo, W. (2026) A Sufficient Condition for the Primality of the Sum of Two Squares. Advances in Pure Mathematics, 16, 412-415.[CrossRef]
[3] Agrawal, M., Kayal, N. and Saxena, N. (2004) Primes Is in P. Annals of Mathematics, 160, 781-793.[CrossRef]
[4] Miller, G.L. (1975) Riemann’s Hypothesis and Tests for Primality. Proceedings of 7th Annual ACM Symposium on Theory of ComputingSTOC ‘75, Albuquerque, 5-7 May 1975, 234-239.[CrossRef]
[5] Rabin, M.O. (1980) Probabilistic Algorithm for Testing Primality. Journal of Number Theory, 12, 128-138.[CrossRef]
[6] Hirschhorn, M.D. (1985) A Simple Proof of Jacobi’s Two-Square Theorem. The American Mathematical Monthly, 92, 579-580.[CrossRef]
[7] Jacobi, C. (1829) Fundamenta Nova Theoriae Functionum Ellipticarum. Bornträger.

Copyright © 2026 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.