Numbers that are perfect squares modulo a given integer, studied via the law of quadratic reciprocity.
IntuitionIntuition: which remainders are perfect squares?
Fix an odd prime p and square every remainder 0,1,…,p−1 modulo p. Because x2≡(p−x)2(modp), the squares repeat in pairs and only about half of the nonzero remainders ever show up. A number a with gcd(a,p)=1 is called a quadratic residue modulo p when the congruence x2≡a(modp) has a solution, and a quadratic nonresidue otherwise. For p=7: squaring 1,2,3,4,5,6 gives 1,4,2,2,4,1, so the quadratic residues modulo 7 are exactly {1,2,4} and the nonresidues are {3,5,6}.
Directed graph of the squaring map modulo a small prime, with quadratic-residue nodes highlighted.
Residue chords modulo m=11: among the 10 nonzero residues, exactly half (1,3,4,5,9) are quadratic residues.
UndergraduateDefinition and the Legendre symbol
Definition: Legendre symbol
For an odd prime p and integer a with p∤a, the Legendre symbol (pa) equals +1 if a is a quadratic residue modulo p, and −1 if it is a quadratic nonresidue. By convention (pa)=0 when p∣a. The Legendre symbol is completely multiplicative in its top argument: (pab)=(pa)(pb).
(pa)≡a2p−1(modp)(Euler’s criterion)
Euler's criterion lets us compute(pa) without factoring anything: raise a to the power 2p−1 modulo p and read off ±1. It also immediately gives the value (p−1)=(−1)2p−1, which tells us that −1 is a quadratic residue exactly for primes p≡1(mod4).
For an odd prime p and gcd(a,p)=1: (pa)≡a2p−1(modp); equivalently, a is a quadratic residue modulo p if and only if a(p−1)/2≡1(modp).
Why is it true?
It turns an existence question (does some x square to a?) into a single modular exponentiation, which is exactly what makes the Legendre symbol computable and multiplicative.
Proof
Since (Z/pZ)∗ is cyclic of order p−1 (a standard fact for prime moduli), fix a primitive root g and write a≡gk(modp) for some 0≤k≤p−2. The quadratic residues modulo p are exactly the even powers of g: if a=g2m then x=gm satisfies x2≡a, and conversely every square x2=(gj)2=g2j is an even power. So a is a quadratic residue exactly when k is even.
Now compute a(p−1)/2≡gk(p−1)/2(modp). If k is even, write k=2m; then gk(p−1)/2=gm(p−1)=(gp−1)m≡1m=1(modp) by Fermat's little theorem, matching the residue case.
If k is odd, then gk(p−1)/2 is a square root of gk(p−1)=(gp−1)k≡1(modp), so a(p−1)/2≡±1. It cannot be 1: if it were, the order of g would have to divide k(p−1)/2, but ord(g)=p−1 and k is odd means k(p−1)/2 is not a multiple of p−1 unless (p−1)/2 already is, contradicting that g is a primitive root of exact order p−1. Hence a(p−1)/2≡−1(modp) exactly when k is odd, i.e. exactly when a is a nonresidue.
Combining both cases: a(p−1)/2≡1(modp) iff a is a quadratic residue, and ≡−1 otherwise, which is precisely the statement (pa)≡a2p−1(modp).
For distinct odd primes p and q: (qp)(pq)=(−1)2p−1⋅2q−1.
Why is it true?
It says whether p is a square mod q and whether q is a square mod p are the same question, up to a sign that depends only on the residues of p,q mod 4 — turning a hard-looking two-variable problem into a one-line rule.
Proof
We use Gauss's lemma as a stepping stone: for an odd prime p and gcd(a,p)=1, look at the least positive residues of a,2a,…,2p−1a modulo p, and let μ be how many of them exceed p/2. Gauss's lemma states (pa)=(−1)μ; it follows from pairing each such "large" residue r with p−r≤p/2 and tracking signs when multiplying the 2p−1 numbers together in two different ways.
Eisenstein's refinement expresses μ as a lattice-point count: one shows μ≡∑k=1(p−1)/2⌊pkq⌋(mod2) when a=q is odd, by comparing ⌊kq/p⌋ (the number of multiples of p below kq) to how far kqmodp sits from p/2. Applying the same counting argument symmetrically gives (pq)=(−1)S(q,p) and (qp)=(−1)S(p,q), where S(q,p)=∑k=1(p−1)/2⌊pkq⌋ and S(p,q)=∑k=1(q−1)/2⌊qkp⌋.
Geometrically, S(q,p)+S(p,q) counts the lattice points (x,y) with 1≤x≤2p−1, 1≤y≤2q−1 lying strictly below the line qx=py (that count is S(q,p)) plus those strictly above it (that count is S(p,q), by the symmetric roles of p,q). No lattice point lies exactly on the line since gcd(p,q)=1 and x<p, so together these two counts exhaust the full rectangle of 2p−1⋅2q−1 lattice points.
Therefore S(q,p)+S(p,q)=2p−1⋅2q−1, and multiplying the two Legendre-symbol formulas gives (qp)(pq)=(−1)S(p,q)+S(q,p)=(−1)2p−1⋅2q−1, which is exactly (qp)(pq)=(−1)2p−1⋅2q−1.
UndergraduateReal-World Applications and Worked Examples
Quadratic residues are not just a number-theory curiosity: they underlie a public-key encryption scheme (Goldwasser–Micali), a widely used pseudorandom bit generator (Blum–Blum–Shub), and the Legendre sequences used to design spread-spectrum radar and GPS-like ranging codes with sharp autocorrelation peaks.
Example: Deciding a quadratic residue by reciprocity
Is 10 a quadratic residue modulo 13?
Solution
Write 10=2⋅5, so (1310)=(132)(135) by multiplicativity.
For (132): since 13≡5(mod8), the supplementary formula for 2 gives (132)=−1.
For (135): since 5≡1(mod4), reciprocity gives (135)(513)=+1, so (135)=(513)=(53) (since 13≡3(mod5)). Squares mod 5 are 1,4, and 3 is not among them, so (53)=−1, hence (135)=−1.
Multiplying: (1310)=(−1)(−1)=+1, so 10is a quadratic residue modulo 13 — indeed 62=36≡10(mod13).
Example: Legendre sequences for spread-spectrum ranging codes
GPS-style ranging systems need binary codes with a sharp autocorrelation peak at zero shift and near-zero correlation elsewhere. Build a length-11 Legendre sequence from the Legendre symbols modulo the prime 11 and check its autocorrelation qualitatively.
Solution
The quadratic residues modulo 11 are {1,3,4,5,9} (squares of 1,…,5), so define si=+1 if i is a residue, si=−1 if i is a nonresidue {2,6,7,8,10}, and s0=−1 by convention, giving the ±1 sequence s=(−1,+1,−1,+1,+1,+1,−1,−1,−1,+1,−1) for i=0,…,10.
The key structural fact is that for a shift k≡0, the correlation ∑isisi+k reduces (using multiplicativity of the Legendre symbol) to a sum closely related to ∑x(11x(x+k)), and a classical character-sum estimate shows such sums equal −1 for every nonzero shift k modulo an odd prime — dramatically smaller than the peak value 10 at k=0.
This two-level autocorrelation (a fixed off-peak value for every nonzero shift) is exactly the property that makes Legendre sequences attractive for synchronizing a receiver: correlating the incoming signal against every cyclic shift of the known sequence produces one unmistakably large spike exactly at the true alignment, which is how a GPS receiver locks onto the timing of a satellite's code.
What is (pa) called when x2≡a(modp) has no solution?
According to Euler's criterion, (pa) is congruent modulo p to which power of a?
For which residue class of an odd prime p modulo 4 is −1 a quadratic residue?
Which cryptographic building block is based directly on the hardness of deciding quadratic residuosity modulo a composite number?