Maths WorkshopMaths problems with full solutions
Exercise 1958Number theory › PrimesOlympiadAdded 4 Nov 2026

Primes 3 mod 4 and sums of two squares

#sum of two squares#quadratic residues#descent

Statement

  1. Let pp be a prime with p≡3(mod4)p\equiv3\pmod4. Prove that if p∣a2+b2p\mid a^2+b^2 then p∣ap\mid a and p∣bp\mid b.
  2. Deduce that if n=a2+b2n=a^2+b^2, every prime p≡3(mod4)p\equiv3\pmod4 divides nn to an even power.
  3. Show that n⋅mn\cdot m is a sum of two squares whenever nn and mm are.
Hint

For part 1, if p∤bp\nmid b use the inverse of bb to get x2≡−1(modp)x^2\equiv-1\pmod p, then apply Fermat's little theorem to xp−1x^{p-1}.

Show solutionHide solution

Solution

1. Suppose p∣a2+b2p\mid a^2+b^2 and p∤bp\nmid b. Let x≡ab−1(modp)x\equiv ab^{-1}\pmod p. Then x2≡−1(modp)x^2\equiv-1\pmod p and x≢0x\not\equiv0. By Fermat's little theorem,
1≡xp−1=(x2)(p−1)/2≡(−1)(p−1)/2(modp).1\equiv x^{p-1}=(x^2)^{(p-1)/2}\equiv(-1)^{(p-1)/2}\pmod p.
Since p≡3(mod4)p\equiv3\pmod4, p−12\frac{p-1}2 is odd, so the right side is −1-1. So 1≡−11\equiv-1, i.e. p=2p=2, contradiction. Hence p∣bp\mid b, and then p∣a2p\mid a^2, so p∣ap\mid a.

2. By strong induction on nn. Let n=a2+b2n=a^2+b^2 and p≡3(mod4)p\equiv3\pmod4 with p∣np\mid n. By part 1, p∣a,bp\mid a,b, so n=p2(a12+b12)n=p^2(a_1^2+b_1^2) where a=pa1a=pa_1, b=pb1b=pb_1, and n/p2n/p^2 is again a sum of two squares, smaller than nn. By induction, the exponent of pp in n/p2n/p^2 is even, so the exponent in nn is even too. (If p∤np\nmid n the exponent is 00.)

3. Brahmagupta's identity:
(a2+b2)(c2+d2)=(ac−bd)2+(ad+bc)2.(a^2+b^2)(c^2+d^2)=(ac-bd)^2+(ad+bc)^2.

Examples. 21=3⋅721=3\cdot7 and 2021=43⋅472021=43\cdot47 are not sums of two squares (primes ≡3(mod4)\equiv3\pmod4 with odd exponent); 45=9⋅5=62+3245=9\cdot5=6^2+3^2 is.

Lesson. To forbid a representation, find a prime for which the representation forces divisibility of both terms, then descend.