Maths WorkshopMaths problems with full solutions
Exercise 1339Number theory › CongruencesOlympiadAdded 5 Nov 2026

The sum of the quadratic residues modulo p

#quadratic residues#sum of squares#divisibility

Statement

Let p≥5p\ge5 be a prime. The nonzero quadratic residues modulo pp are the residues r∈{1,…,p−1}r\in\{1,\dots,p-1\} for which x2≡r(modp)x^2\equiv r\pmod p has a solution. Prove that the sum of all of them is divisible by pp.

Hint

Show first that the residues are exactly the squares 12,22,…,m21^2,2^2,\dots,m^2 with m=p−12m=\frac{p-1}2, all distinct modulo pp.

Show solutionHide solution

Solution

Step 1: there are exactly mm residues, represented by 12,…,m21^2,\dots,m^2. Any x≢0x\not\equiv0 is congruent to ±j\pm j for some j∈{1,…,m}j\in\{1,\dots,m\}, so x2≡j2x^2\equiv j^2. For 1≤i<j≤m1\le i<j\le m, j2−i2=(j−i)(j+i)j^2-i^2=(j-i)(j+i) with 0<j−i<p0<j-i<p and 0<j+i≤p−1<p0<j+i\le p-1<p, so p∤j2−i2p\nmid j^2-i^2: the squares are distinct modulo pp.

Step 2: the sum. Each residue rr is congruent to some j2j^2, so
∑r≡∑j=1mj2=m(m+1)(2m+1)6=p (p−1)(p+1)24(modp),\sum r\equiv\sum_{j=1}^mj^2=\frac{m(m+1)(2m+1)}6=\frac{p\,(p-1)(p+1)}{24}\pmod p,
using m=p−12m=\frac{p-1}2, m+1=p+12m+1=\frac{p+1}2, 2m+1=p2m+1=p.

Step 3: divisibility. For a prime p≥5p\ge5, pp is odd and not a multiple of 33, so (p−1)(p+1)(p-1)(p+1) is divisible by 88 and by 33. Hence 24∣(p−1)(p+1)24\mid(p-1)(p+1) and p(p−1)(p+1)24=p⋅p2−124\frac{p(p-1)(p+1)}{24}=p\cdot\frac{p^2-1}{24} is a multiple of pp.

Check. p=7p=7: residues 1,2,41,2,4, sum 77 ✓. p=11p=11: residues 1,3,4,5,91,3,4,5,9, sum 2222 ✓.

Lesson. To sum a set of residues, replace each by a convenient representative, here the squares j2j^2 with j≤p−12j\le\frac{p-1}2.