Although quadratic residues appear to occur in a rather random pattern modulo
n, and this has been exploited in such
applications as
acoustics and
cryptography, their distribution also exhibits some striking regularities. Using
Dirichlet's theorem on primes in
arithmetic progressions, the
law of quadratic reciprocity, and the
Chinese remainder theorem (CRT) it is easy to see that for any
M > 0 there are primes
p such that the numbers 1, 2, ...,
M are all residues modulo
p. For example, if
p ≡ 1 (mod 8), (mod 12), (mod 5) and (mod 28), then by the law of quadratic reciprocity 2, 3, 5, and 7 will all be residues modulo
p, and thus all numbers 1–10 will be. The CRT says that this is the same as
p ≡ 1 (mod 840), and Dirichlet's theorem says there are an infinite number of primes of this form. 2521 is the smallest, and indeed 12 ≡ 1, 10462 ≡ 2, 1232 ≡ 3, 22 ≡ 4, 6432 ≡ 5, 872 ≡ 6, 6682 ≡ 7, 4292 ≡ 8, 32 ≡ 9, and 5292 ≡ 10 (mod 2521).
Dirichlet's formulas The first of these regularities stems from
Peter Gustav Lejeune Dirichlet's work (in the 1830s) on the
analytic formula for the
class number of binary
quadratic forms. Let
q be a prime number,
s a complex variable, and define a
Dirichlet L-function as :L(s) = \sum_{n=1}^\infty\left(\frac{n}{q}\right)n^{-s}. Dirichlet showed that if
q ≡ 3 (mod 4), then :L(1) = -\frac{\pi}{\sqrt q}\sum_{n=1}^{q-1} \frac{n}{q} \left(\frac{n}{q}\right) > 0. Therefore, in this case (prime
q ≡ 3 (mod 4)), the sum of the quadratic residues minus the sum of the nonresidues in the range 1, 2, ...,
q − 1 is a negative number. For example, modulo 11, :
1, 2,
3,
4,
5, 6, 7, 8,
9, 10 (residues in
bold) :1 + 4 + 9 + 5 + 3 = 22, 2 + 6 + 7 + 8 + 10 = 33, and the difference is −11. In fact the difference will always be an odd multiple of
q if
q > 3. In contrast, for prime
q ≡ 1 (mod 4), the sum of the quadratic residues minus the sum of the nonresidues in the range 1, 2, ...,
q − 1 is zero, implying that both sums equal \frac{q(q-1)}{4}. Dirichlet also proved that for prime
q ≡ 3 (mod 4), :L(1) = \frac{\pi}{\left(2-\left(\frac{2}{q}\right)\right)\!\sqrt q}\sum_{n=1}^\frac{q-1}{2}\left(\frac{n}{q}\right) > 0. This implies that there are more quadratic residues than nonresidues among the numbers 1, 2, ..., (
q − 1)/2. For example, modulo 11 there are four residues less than 6 (namely 1, 3, 4, and 5), but only one nonresidue (2). An intriguing fact about these two theorems is that all known proofs rely on analysis; no-one has ever published a simple or direct proof of either statement.
Law of quadratic reciprocity If
p and
q are odd primes, then: ((
p is a quadratic residue mod
q) if and only if (
q is a quadratic residue mod
p)) if and only if (at least one of
p and
q is congruent to 1 mod 4). That is: : \left(\frac{p}{q}\right) \left(\frac{q}{p}\right) = (-1)^{\frac{p-1}{2} \cdot \frac{q-1}{2}} where \left(\frac{p}{q}\right) is the
Legendre symbol. Thus, for numbers
a and odd primes
p that don't divide
a:
Pairs of residues and nonresidues Modulo a prime
p, the number of pairs
n,
n + 1 where
n R
p and
n + 1 R
p, or
n N
p and
n + 1 R
p, etc., are almost equal. More precisely, let
p be an odd prime. For
i,
j = 0, 1 define the sets :A_{ij}=\left\{k\in\{1,2,\dots,p-2\}: \left(\frac{k}{p}\right)=(-1)^i\land\left(\frac{k+1}{p}\right)=(-1)^j\right\}, and let :\alpha_{ij} = |A_{ij}|. That is, :α00 is the number of residues that are followed by a residue, :α01 is the number of residues that are followed by a nonresidue, :α10 is the number of nonresidues that are followed by a residue, and :α11 is the number of nonresidues that are followed by a nonresidue. Then if
p ≡ 1 (mod 4) :\alpha_{00} = \frac{p-5}{4},\;\alpha_{01} =\alpha_{10} =\alpha_{11} = \frac{p-1}{4} and if
p ≡ 3 (mod 4) :\alpha_{01} = \frac{p+1}{4},\;\alpha_{00} =\alpha_{10} =\alpha_{11} = \frac{p-3}{4}. For example: (residues in
bold) Modulo 17 :
1,
2, 3,
4, 5, 6, 7,
8,
9, 10, 11, 12,
13, 14,
15,
16 ::
A00 = {1,8,15}, ::
A01 = {2,4,9,13}, ::
A10 = {3,7,12,14}, ::
A11 = {5,6,10,11}. Modulo 19 :
1, 2, 3,
4,
5,
6,
7, 8,
9, 10,
11, 12, 13, 14, 15,
16,
17, 18 ::
A00 = {4,5,6,16}, ::
A01 = {1,7,9,11,17}, ::
A10 = {3,8,10,15}, ::
A11 = {2,12,13,14}. Gauss (1828) introduced this sort of counting when he proved that if
p ≡ 1 (mod 4) then
x4 ≡ 2 (mod
p) can be solved if and only if
p =
a2 + 64
b2.
Pólya–Vinogradov inequality The values of (\tfrac{a}{p}) for consecutive values of
a mimic a random variable like a
coin flip. Specifically,
Pólya and
Vinogradov proved (independently) in 1918 that for any nonprincipal
Dirichlet character χ(
n) modulo
q and any integers
M and
N, : \left|\sum_{n=M+1}^{M+N}\chi(n)\right| =O\left( \sqrt q \log q\right), in
big O notation. Setting : \chi(n) = \left(\frac{n}{q}\right), this shows that the number of quadratic residues modulo
q in any interval of length
N is : \frac{1}{2}N + O(\sqrt q\log q). It is easy to prove that : \left| \sum_{n=M+1}^{M+N} \left( \frac{n}{q} \right) \right| In fact, : \left| \sum_{n=M+1}^{M+N} \left( \frac{n}{q} \right) \right|
Montgomery and
Vaughan improved this in 1977, showing that, if the
generalized Riemann hypothesis is true then : \left|\sum_{n=M+1}^{M+N}\chi(n)\right|=O\left(\sqrt q \log \log q\right). This result cannot be substantially improved, for
Schur had proved in 1918 that : \max_N \left|\sum_{n=1}^{N}\left(\frac{n}{q}\right)\right|>\frac{1}{2\pi}\sqrt q and
Paley had proved in 1932 that : \max_N \left|\sum_{n=1}^{N}\left(\frac{d}{n}\right)\right|>\frac{1}{7}\sqrt d \log \log d for infinitely many
d > 0.
Least quadratic non-residue The least quadratic residue mod
p is clearly 1. The question of the magnitude of the least quadratic non-residue
n(
p) is more subtle, but it is always prime, with 7 appearing for the first time at 71. The Pólya–Vinogradov inequality above gives . The best unconditional estimate is
n(
p) ≪
pθ for any , obtained by estimates of Burgess on
character sums.
Linnik showed that the number of
p less than
X such that
n(
p) > Xε is bounded by a constant depending on ε. The least quadratic non-residues mod
p for odd primes
p are: : 2, 2, 3, 2, 2, 3, 2, 5, 2, 3, 2, ...
Quadratic excess Let
p be an odd prime. The
quadratic excess E(
p) is the number of quadratic residues on the range (0,
p/2) minus the number in the range (
p/2,
p) . For
p congruent to 1 mod 4, the excess is zero, since −1 is a quadratic residue and the residues are symmetric under
r ↔
p−
r. For
p congruent to 3 mod 4, the excess
E is always positive. == Computational complexity ==