Congruence modulo *n* is an equivalence relation on the integers. It partitions the integers into *n* equivalence classes. The equivalence classes are called the *residues modulo n*. Any member of a residue is a *representative*.

Arithmetic can be defined on residues.

# Addition, Additive Inverse, and Multiplication

Sometimes we can perform operations on representatives of the residues using customary integer operations and the result will be a representative of the residue we would have got if we performed the corresponding operations on the residue classes.

This is true for addition and multiplication and we can use this to show that addition and multiplication on residues are both associative and commutative. They also observe the distributive law.

The additive identity is the reside class with zero in it. The additive inverse residue exists and can be found by computing the additive inverse of a representative.

In summary, the residues modulo n are a commutative ring with identity and addition, negation, and multiplication can be calculated by doing the corresponding operations on representatives.

# Exponentiation

Exponentiation can be calculated using multiplication, so the preceding section shows us that we can compute exponentiation on a residue by using a representative. Note that the base is a residue, but the exponent is an integer.

There is a shortcut for computing exponents due to Euler

(1)The congruence allows us to compute any exponent with fewer than *φ(n)* multiplications.

The function *φ* is called Euler's totient, and is

where the product is over all primes that divide *n*. When *n* is itself prime, Euler's Theorem reduces to Fermat's Little Theorem:

# Multiplicative Inverse and Division

Division on the integers is often not defined. An integer *a* is *divisible by b* if there is another integer *m* such that:

Multiplicative inverses for most integers don't exist. The exceptions are 1 and -1, which are their own inverses.

For residues, the situation is better. A nonzero residue *a* modulo *n* has a multiplicative inverse if and only if *a* and *n* are relatively prime. The extended Euclidean algorithm will find *x* and *y* such that *ax + ny = 1*, and thus *x* is the multiplicative inverse of *a*.

If the modulus *n* is prime, then all nonzero residues have multiplicative inverses and the residues are a field.

If *n* is not prime, the residues are not an integral domain and cancellation is not always possible. If *d* is the greatest common divisor of *a* and *n*, then for all *z* and *z'* we have this result:

If *a* and *n* are relatively prime, which means *d* is 1, we can cancel *a* from both sides of the equation.

# Square Roots

Non-zero complex numbers have two square roots.

Positive real numbers have two square roots and negative real numbers have none.

Positive integers have two square roots if they are perfect squares, otherwise they have none.

Non-zero residues have either two square roots or none. In the former case, the residue is said to be a *quadratic residue* and in the latter case a *quadratic nonresidue*. Determining whether a residue is a quadratic residue is complicated. The following notation, called the *Legendre symbol*, is used when *p* is an odd prime:

The following always hold:

(7)When *a* and *p* are relatively prime then

The *Jacobi symbol* is a generalization of the Legendre symbol where *p* is replaced by any positive odd integer *n*. The *Kronecker symbol* is a further generalization where *n* can be any non-zero integer.

The quadratic reciprocity law states that for odd primes *q* and *p* which both are are of the form *4k +3*, then exactly one of the following congruences has a solution:

Moreover, if *q* and *p* are odd primes not both of the form *4k + 3*, then both congruences are solvable or both congruences are not.

How the quadratic reciprocity law is used:

(11)*non-prime residue*

*modulus 2*

*non-prime modulus*

*quadratic equation*

*how to find the square roots*

# Discrete Logarithm

The discrete log of *g* base *b*, where both *g* and *b* are residues, is an integer *k* such at *b ^{k} = g*. A brute force search has run time which is linear in the size of the multiplicative group, or exponential in the number of digits in the size of the multiplicative group. Better algorithms exist, but none are polynomial in the number of digits in the size of the multiplicative group.

# Chinese Remainder Theorem

If we have multiple equations with the same modulus, we can use substitution to find a solution.

If the moduli on the equations are different, the Chinese Remainder Theorem tells us there is a solution under certain conditions. In particular there is a solution *a* to the following system of equations, provided that the n_{i} are all pairwise relatively prime:

Moreover, if *a* and *a'* are two solutions, then: