Quadratic Residues

Let nn be a positive integer and let aa be an integer such that gcd(a,n)=1gcd(a, n) = 1.

aa is said to be a quadratic residue modulo nn if and only if there exists a xx such that: x2a(modn)x² \equiv a (mod n)

When nn is a prime number (n=p)(n = p) there exist three cases:

  1. either aa is a multiple of pp, or

  2. aa is a quadratic residue, or

  3. aa is not a quadratic residue.

The Legendre symbol (ap)(\frac{a}{p}) captures this as follows.

Legendre Symbol

Jacobi Symbol

Counts

For a prime pp, the number of integers belonging to the set [1,2,...,p1][1, 2, . . . , p − 1] that are quadratic residues is exactly (p1)/2(p − 1)/2.

How about composite numbers that are the product of two distinct prime numbers?

Square Roots

Example:

Factorization

Example (continuation of the code of the previous slide):

pari-gp can only compute square roots when the modulus is prime:

Last updated