Quadratic residue


In number theory, an integer q is a quadratic residue modulo n if it is congruent to a perfect square modulo n; that is, if there exists an integer x such that
Otherwise, q is a quadratic nonresidue modulo n.
Quadratic residues are used in [|applications] ranging from acoustical engineering to [|cryptography] and the factoring of large numbers.

History, conventions, and elementary facts

, Euler, Lagrange, Legendre, and other number theorists of the 17th and 18th centuries established theorems and formed conjectures about quadratic residues, but the first systematic treatment is § IV of Gauss's Disquisitiones Arithmeticae. Article 95 introduces the terminology "quadratic residue" and "quadratic nonresidue", and says that if the context makes it clear, the adjective "quadratic" may be dropped.
For a given n, a list of the quadratic residues modulo n may be obtained by simply squaring all the numbers 0, 1,...,. Since a≡''b implies a''2b2, any other quadratic residue is congruent to some in the obtained list. But the obtained list is not composed of mutually incongruent quadratic residues only. Since a22, the list obtained by squaring all numbers in the list 1, 2,..., is symmetric around its midpoint, hence it is actually only needed to square all the numbers in the list 0, 1,..., n/2. The list so obtained may still contain mutually congruent numbers. Thus, the number of mutually noncongruent quadratic residues modulo n cannot exceed n/2 + 1 or /2.
The product of two residues is always a residue.

Prime modulus

Modulo an odd prime number p there are /2 residues and /2 nonresidues, by Euler's criterion. In this case, it is customary to consider 0 as a special case and work within the multiplicative group of nonzero elements of the field. In other words, every congruence class except zero modulo p has a multiplicative inverse. This is not true for composite moduli.
Following this convention, the multiplicative inverse of a residue is a residue, and the inverse of a nonresidue is a nonresidue.
Following this convention, modulo an odd prime number there is an equal number of residues and nonresidues.
Modulo a prime, the product of two nonresidues is a residue and the product of a nonresidue and a residue is a nonresidue.
The first supplement to the law of quadratic reciprocity is that if p ≡ 1 then −1 is a quadratic residue modulo p, and if p ≡ 3 then −1 is a nonresidue modulo p. This implies the following:
If p ≡ 1 the negative of a residue modulo p is a residue and the negative of a nonresidue is a nonresidue.
If p ≡ 3 the negative of a residue modulo p is a nonresidue and the negative of a nonresidue is a residue.

Prime power modulus

All odd squares are ≡ 1 and thus also ≡ 1. If a is an odd number and m = 8, 16, or some higher power of 2, then a is a residue modulo m if and only if a ≡ 1.
For example, mod the odd squares are
and the even ones are

So a nonzero number is a residue mod 8, 16, etc., if and only if it is of the form 4k.
A number a relatively prime to an odd prime p is a residue modulo any power of p if and only if it is a residue modulo p.
If the modulus is pn,
Notice that the rules are different for powers of two and powers of odd primes.
Modulo an odd prime power n = pk, the products of residues and nonresidues relatively prime to p obey the same rules as they do mod p; p is a nonresidue, and in general all the residues and nonresidues obey the same rules, except that the products will be zero if the power of p in the product ≥ n.
Modulo 8, the product of the nonresidues 3 and 5 is the nonresidue 7, and likewise for permutations of 3, 5 and 7. In fact, the multiplicative group of the non-residues and 1 form the Klein four-group.

Composite modulus not a prime power

The basic fact in this case is
Modulo a composite number, the product of two residues is a residue. The product of a residue and a nonresidue may be a residue, a nonresidue, or zero.

For example, from the table for modulus 6
1, 2, 3, 4, 5.
The product of the residue 3 and the nonresidue 5 is the residue 3, whereas the product of the residue 4 and the nonresidue 2 is the nonresidue 2.

Also, the product of two nonresidues may be either a residue, a nonresidue, or zero.

For example, from the table for modulus 15
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14.
The product of the nonresidues 2 and 8 is the residue 1, whereas the product of the nonresidues 2 and 7 is the nonresidue 14.

This phenomenon can best be described using the vocabulary of abstract algebra. The congruence classes relatively prime to the modulus are a group under multiplication, called the group of units of the ring, and the squares are a subgroup of it. Different nonresidues may belong to different cosets, and there is no simple rule that predicts which one their product will be in. Modulo a prime, there is only the subgroup of squares and a single coset.
The fact that, e.g., modulo 15 the product of the nonresidues 3 and 5, or of the nonresidue 5 and the residue 9, or the two residues 9 and 10 are all zero comes from working in the full ring, which has zero divisors for composite n.
For this reason some authors add to the definition that a quadratic residue a must not only be a square but must also be relatively prime to the modulus n.
Although it makes things tidier, this article does not insist that residues must be coprime to the modulus.

Notations

Gauss used and to denote residuosity and non-residuosity, respectively;
Although this notation is compact and convenient for some purposes, a more useful notation is the Legendre symbol, also called the quadratic character, which is defined for all integers and positive odd prime numbers as
There are two reasons why numbers ≡ 0 are treated specially. As we have seen, it makes many formulas and theorems easier to state. The other reason is that the quadratic character is a homomorphism from the multiplicative group of nonzero congruence classes modulo to the complex numbers under multiplication. Setting allows its domain to be extended to the multiplicative semigroup of all the integers.
One advantage of this notation over Gauss's is that the Legendre symbol is a function that can be used in formulas. It can also easily be generalized to cubic, quartic and higher power residues.
There is a generalization of the Legendre symbol for composite values of, the Jacobi symbol, but its properties are not as simple: if is composite and the Jacobi symbol then, and if then but if we do not know whether or. For example: and, but and. If is prime, the Jacobi and Legendre symbols agree.

Distribution of quadratic residues

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 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,, and, 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, 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.

Dirichlet's formulas

The first of these regularities stems from Peter Gustav Lejeune Dirichlet's work 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
Dirichlet showed that if q ≡ 3, then
Therefore, in this case, 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,
In fact the difference will always be an odd multiple of q if q > 3. In contrast, for prime q ≡ 1, 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.
Dirichlet also proved that for prime q ≡ 3,
This implies that there are more quadratic residues than nonresidues among the numbers 1, 2,..., /2.
For example, modulo 11 there are four residues less than 6, but only one nonresidue.

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:
if and only if ) if and only if.
That is:
where is the Legendre symbol.
Thus, for numbers a and odd primes p that don't divide a:
aa is a quadratic residue mod p if and only ifaa is a quadratic residue mod p if and only if
1−1p ≡ 1
2p ≡ 1, 7 −2p ≡ 1, 3
3p ≡ 1, 11 −3p ≡ 1
4−4p ≡ 1
5p ≡ 1, 4 −5p ≡ 1, 3, 7, 9
6p ≡ 1, 5, 19, 23 −6p ≡ 1, 5, 7, 11
7p ≡ 1, 3, 9, 19, 25, 27 −7p ≡ 1, 2, 4
8p ≡ 1, 7 −8p ≡ 1, 3
9−9p ≡ 1
10p ≡ 1, 3, 9, 13, 27, 31, 37, 39 −10p ≡ 1, 7, 9, 11, 13, 19, 23, 37
11p ≡ 1, 5, 7, 9, 19, 25, 35, 37, 39, 43 −11p ≡ 1, 3, 4, 5, 9
12p ≡ 1, 11 −12p ≡ 1