Ent 05
Ent 05
In view of (5.1), we have y12 + y22 ≡ x21 + x22 ≡ 0 mod m, so there exists m0 ∈ Z such that
(5.4) y12 + y22 = mm0 .
Combining (5.2)–(5.4), we have
! m "2
m2 ! m "2
mm0 ! , + =
2 2 2
so that m0 < m. On the other hand, we must have m0 $= 0, for otherwise y1 = y2 = 0, so that
x1 ≡ x2 ≡ 0 mod m, and so m2 | (x21 + x22 ), whence m | p, contradicting that 1 < m < p. We
therefore must have 1 ! m0 < m. Combining (5.1) and (5.4), we now have
(5.5) m0 pm2 = (x21 + x22 )(y12 + y22 ) = (x1 y1 + x2 y2 )2 + (x1 y2 − x2 y1 )2 .
By (5.1)–(5.3), we have
x1 y1 + x2 y2 ≡ x21 + x22 ≡ 0 mod m,
and
x1 y2 − x2 y1 ≡ x1 x2 − x2 x1 ≡ 0 mod m.
It follows that each term on the right-hand side of (5.5) is divisible by m2 , so that
# $2 # $2
x1 y1 + x2 y2 x1 y2 − x2 y1
m0 p = + ,
m m
and the proof is complete. %
We now determine all the natural numbers which are sums of two integer squares.
Theorem 5.2. Suppose that n ∈ N and n > 1, and the canonical decomposition of n is given by
n = 2r pr11 . . . prkk q1s1 . . . q!s! ,
where the integer r " 0 and r1 , . . . , rk , s1 , . . . , s! ∈ N, and p1 , . . . , pk , q1 , . . . , q! ∈ N are primes
satisfying p1 ≡ . . . ≡ pk ≡ 1 mod 4 and q1 ≡ . . . ≡ q! ≡ 3 mod 4. Then n is a sum of two integer
squares if and only if s1 , . . . , s! are all even.
Proof. Suppose first of all that n = x21 + x22 , where x1 , x2 ∈ Z. Then
(5.6) x21 + x22 ≡ 0 mod q1 .
Suppose on the contrary that s1 is odd. If q1 ! x2 , then it follows from Theorem 3.8 that there exists
x ∈ Z such that x2 x ≡ 1 mod q1 . Multiplying (5.6) by x2 gives (x1 x)2 ≡ −1 mod q1 , impossible
since −1 is a quadratic non-residue modulo q1 . It follows that q1 | x2 , and so q1 | x1 also. Writing
x1 = q1 y1 and x2 = q1 y2 , we have n = q12 (y12 + y22 ). Hence s1 " 3. Repeating the argument on
n/q12 yields s1 − 2 " 3. Repeating the argument a sufficient number of times leads eventually to a
contradiction. It follows that s1 must be even. A similar argument shows that s2 , . . . , s! are all even.
The converse follows from the identity
(5.7) (x21 + x22 )(y12 + y22 ) = (x1 y1 + x2 y2 )2 + (x1 y2 − x2 y1 )2 ,
on noting that we can apply Theorem 5.1 to each of the primes p1 , . . . , pk , that 2 is a sum of two
integer squares, and that qj2 = qj2 + 02 is a sum of two integer squares for every j = 1, . . . , !. %
is soluble. We now show that if x ∈ Z is a solution of (5.8), then there exist a, b ∈ Z such that
1 1
(5.9) |a| < p 2 , |b| < p 2 , ab $= 0 and ax ≡ b mod p.
If (5.9) holds, then 0 < a2 + b2 < 2p and
a2 + b2 ≡ a2 + (ax)2 = a2 (1 + x2 ) ≡ 0 mod p,
so that a2 + b2 = p. To prove (5.9), consider the numbers of the form ux − v, where u, v ∈ Z satisfy
1 1 1
0 ! u ! p 2 and 0 ! v ! p 2 . There are ([p 2 ] + 1)2 > p choices of such numbers u and v, and only
p residue classes modulo p. It follows from Dirichlet’s box principle that there exist two such pairs
u# , v # and u## , v ## such that u# x − v # and u## x − v ## belong to the same residue class modulo p and so
are congruent to each other modulo p. Now let a = u# − u## and b = v # − v ## . Then
ax − b = (u# − u## )x − (v # − v ## ) ≡ 0 mod p.
1 1
Clearly we have |a| < p 2 and |b| < p 2 . Finally, if b = 0, then we must have a ≡ 0 mod p, and so
a = 0, a contradiction. Hence b $= 0. Similarly a $= 0. %
Our first step towards finding a formula for the number of representations of a natural number as
a sum of two integer squares is the following generalization of the above proof of Fermat’s theorem.
Theorem 5.3. Suppose that n ∈ N and n > 1. For every solution x ∈ Z of the congruence
x2 + 1 ≡ 0 mod n, there exist unique positive integers a, b ∈ N such that
(5.10) (a, b) = 1, a2 + b2 = n and ax ≡ b mod n.
1
Proof. By considering numbers of the form ux − v, where u, v ∈ Z satisfy 0 ! u ! n 2 and
1
0 ! v ! n 2 , we can show as before that there exist non-zero numbers α, β ∈ Z such that
α2 + β 2 = n and αx ≡ β mod n.
Clearly, we may assume without loss of generality that α > 0.
If β > 0, then we let a = α and b = β. Clearly a2 + b2 = n and ax ≡ b mod n.
If β < 0, then we let a = −β and b = α. Again we have a2 + b2 = n. On the other hand, we have
bx ≡ −a mod n, so that bx2 ≡ −ax mod n. It now follows from the assumption x2 ≡ −1 mod n that
ax ≡ b mod n.
To show that (a, b) = 1, note that there exist k, ! ∈ Z such that
x2 + 1 = kn and b = ax + !n.
It follows that
n = a2 + b2 = a2 + (ax + !n)2 = a2 (1 + x2 ) + ax!n + (ax + !n)!n
= a2 kn + ax!n + b!n = (a(ak + x!) + b!)n,
and so a(ak + x!) + b! = 1, whence (a, b) = 1.
Finally, to show uniqueness, suppose that the conclusion holds also for the pair A, B ∈ N. Then
n2 = (a2 + b2 )(A2 + B 2 ) = (aA + bB)2 + (aB − bA)2 .
It follows that 0 < aA + bB ! n. On the other hand, note that
aA + bB ≡ aA + aAx2 = aA(1 + x2 ) ≡ 0 mod n.
We therefore must have aA + bB = n, and so aB − bA = 0. Since (a, b) = (A, B) = 1, we must
therefore have a = A and b = B. %
Theorem 5.4. Suppose that n ∈ N, and T (n) is equal to the number of solutions of the congruence
x2 + 1 ≡ 0 mod n. Then the number of solutions of the equation n = a2 + b2 with (a, b) = 1 is equal
to 4T (n).
Proof. Suppose first of all that n = 1. Clearly T (1) = 1 and the equation 1 = a2 + b2 has four
solutions, namely (a, b) = (±1, 0) and (a, b) = (0, ±1).
Suppose now that n > 1. We have already shown that for every solution x ∈ Z of the congruence
x2 + 1 ≡ 0 mod n, there exist unique positive integers a, b ∈ N such that (5.10) holds. Conversely,
suppose that a, b ∈ N satisfy (a, b) = 1 and n = a2 + b2 . It is easy to see that (a, n) = 1, and so the
congruence ax ≡ b mod n has unique solution.
36 5. SUMS OF INTEGER SQUARES
The above establishes a one-to-one correspondence between the solutions of x2 + 1 ≡ 0 mod n and
numbers a, b ∈ N such that (a, b) = 1 and n = a2 + b2 . The factor 4 occurs if we permit negative
values for a and b. %
Theorem 5.5. Suppose that n ∈ N, and T (n) is equal to the number of solutions of the congruence
x2 + 1 ≡ 0 mod n. Then T (n) = 0 if 4 | n or if n is divisible by a prime q ≡ 3 mod 4. Otherwise we
have T (n) = 2k , where k is the number of distinct odd prime factors of n.
Proof. Clearly the result is valid if n = 1, so we assume that n > 1. It is not too difficult to show
that T (n) is a multiplicative function. It follows that if the canonical decomposition of n is given by
n = 2r pr11 . . . prkk q1s1 . . . q!s! ,
where the integer r " 0 and r1 , . . . , rk , s1 , . . . , s! ∈ N, and p1 , . . . , pk , q1 , . . . , q! ∈ N are primes
satisfying p1 ≡ . . . ≡ pk ≡ 1 mod 4 and q1 ≡ . . . ≡ q! ≡ 3 mod 4, then
T (n) = T (2r )T (pr11 ) . . . T (prkk )T (q1s1 ) . . . T (q!s! ).
It is easy to check that T (2) = 1. Also, the congruence x2 ≡ −1 mod 4 has no solutions, and so
the congruence x2 ≡ −1 mod 2r has no solutions for any r " 2. Hence T (2r ) = 0 for every r " 2,
and so T (n) = 0 if 4 | n.
Suppose next that q ∈ N is a prime satisfying q ≡ 3 mod 4. Since −1 is a quadratic non-residue
modulo q, it follows that the congruence x2 ≡ −1 mod q has no solutions, and so the congruence
x2 ≡ −1 mod q s has no solutions for any s " 1. Hence T (q s ) = 0 for every s " 1, and so T (n) = 0 if
q | n.
To complete the proof, it suffices to show that for every prime p ∈ N satisfying p ≡ 1 mod 4,
we have T (pr ) = 2 for every r " 1. Suppose that r ∈ N is fixed. Any solution of the congruence
x2 ≡ −1 mod pr can be assumed to be an element in the set
R = {x ∈ N : 0 < x < pr , p ! x}.
Now any x ∈ R must satisfy the congruence x2 ≡ m mod pr for some number m ∈ N satisfying
0 < m < pr and (m/p)L = 1. There are 12 (p − 1) numbers m ∈ N satisfying 0 < m < p and
(m/p)L = 1, and so there are 12 (p − 1)pr−1 = 12 φ(pr ) numbers m ∈ N satisfying 0 < m < pr and
(m/p)L = 1. Suppose now that x2 ≡ y 2 mod pr and p ! x. Then pr | (x + y)(x − y), so that p | (x + y)
or p | (x − y); but not both, for otherwise p must divide their sum 2x, a contradiction. It follows
that pr | (x + y) or pr | (x − y), and so x ≡ ±y mod pr . Hence for each of the 12 φ(pr ) numbers
m ∈ N satisfying 0 < m < pr and (m/p)L = 1, there are at most two numbers x ∈ R such that
x2 ≡ m mod pr . Since R contains precisely φ(pr ) elements, it follows that for each of the 12 φ(pr )
numbers m ∈ N satisfying 0 < m < pr and (m/p)L = 1, there are precisely two numbers x ∈ R such
that x2 ≡ m mod pr . Note now that −1 is a quadratic residue modulo p. It follows that there are
precisely two numbers x ∈ R such that x2 ≡ −1 mod pr , and so T (pr ) = 2. %
Theorem 5.6. Suppose that n ∈ N, and S(n) is equal to the number of solutions of the equation
n = a2 + b2 in numbers a, b ∈ Z. Then
& !n"
S(n) = 4 T ,
2
d2
d |n
where for every n ∈ N, the number T (n) is equal to the number of solutions of the congruence
x2 + 1 ≡ 0 mod n.
Proof. Suppose that a, b ∈ Z satisfy d = (a, b). Clearly d2 | n. Now write a1 = a/d and b1 = b/d,
and identify the pair a, b with the pair a1 , b1 , where clearly
n
= a21 + b21 and (a1 , b1 ) = 1.
d2
The result now follows on noting Theorem 5.4. %
By the non-principal character modulo 4, we mean the function χ : N → R, defined for every m ∈ N
by
0, if m ≡ 0 mod 2,
χ(m) = 1, if m ≡ 1 mod 4,
−1, if m ≡ 3 mod 4.
5.2. NUMBER OF REPRESENTATIONS 37
Theorem 5.7. Suppose that n ∈ N, and S(n) is equal to the number of solutions of the equation
n = a2 + b2 in numbers a, b ∈ Z. Then
&
S(n) = 4 χ(m),
m|n
It is not difficult to show that the function χ(n) is multiplicative, and so it follows from Theorem 2.1
that the function W (n) is also multiplicative. On the other hand, recall that the function T (n) is
multiplicative. It follows from Theorem 5.6, in a way similar to the proof of Theorem 2.1, that if
(n1 , n2 ) = 1, then
S(n1 n2 ) S(n1 ) S(n2 )
= .
4 4 4
To complete the proof, it therefore suffices to show that for any prime p ∈ N and any r ∈ N, we have
S(pr )
= W (pr ),
4
since the result is obvious for n = 1.
Consider first of all
S(pr ) & # pr $
= T .
4 2 r
d2
d |p
If r is even, then
S(pr ) 1, if p = 2,
= T (pr ) + T (pr−2 ) + . . . + T (p2 ) + T (1) = 1, if p ≡ 3 mod 4,
4
r + 1, if p ≡ 1 mod 4.
If r is odd, then
S(pr ) 1, if p = 2,
= T (pr ) + T (pr−2 ) + . . . + T (p3 ) + T (p) = 0, if p ≡ 3 mod 4,
4
r + 1, if p ≡ 1 mod 4.
Hence
1,
if p = 2,
S(pr ) 1, if p ≡ 3 mod 4 and r is even,
=
4
0, if p ≡ 3 mod 4 and r is odd,
r + 1, if p ≡ 1 mod 4.
Consider next W (pr ) = χ(pr ) + . . . + χ(p) + 1. We can show that χ(pu ) = (χ(p))u for every u ∈ N.
Hence
1, if p = 2,
1, if p ≡ 3 mod 4 and r is even,
W (p ) = (χ(p)) + . . . + χ(p) + 1 =
r r
0, if p ≡ 3 mod 4 and r is odd,
r + 1, if p ≡ 1 mod 4.
This completes the proof. %
Remark. The above treatment is due to Landau (1927) and is likely to have been influenced by
Dirichlet’s work concerning primes in arithmetic progressions.
38 5. SUMS OF INTEGER SQUARES