Integer division takes two integers, the dividend and divisor, and yields two integers, the quotient and remainder, where the remainder is non-negative and smaller than the divisor. If two dividends have the same remainder when divided by the same divsior n, we say that they are congruent modulo n.
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 repeated 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 when a and n are relatively prime:
(1)The congruence allows us to compute any exponent with fewer than φ(n) multiplications.
The function φ is called Euler's totient, and it counts the positive integers less than or equal to n which are relatively prime to n. An expression for the totient is
(2)where the product is over all primes that divide n. When n is itself prime, Euler's Theorem reduces to Fermat's Little Theorem:
(3)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:
(4)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 of a nonzero factor 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:
(5)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 in the complex numbers.
Positive real numbers have two square roots in the real numbers and negative real numbers have none.
Positive integers have two square roots in the integers if they are perfect squares, otherwise they have none.
The single non-zero residue modulo 2 has one square root.
Non-zero residues (p > 2) 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:
(6)The following always hold:
(7)When a and p are relatively prime then
(8)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:
(9)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)If a is a quadratic residue of an odd prime p congruent to 3 modulo 4, then
(13)If a is a quadratic residue of an odd prime p congruent to 5 modulo 8, then
(14)There is no known formula when a is a quadratic residue of an odd prime p congruent to 1 modulo 8. The Tonelli-Shanks algorithm offers a method for finding a solution, however.
Finding square roots is a special case of finding the roots of a polynomial. If f(x) is a polynomial with integer coefficients, then Hensel's lemma provides a way subject to some conditions of calculating roots module pk+m, m ≤ k, when we know a root for f(x) modulo pk.
If f(x) is a polynomial with integer coefficients, then Hensel's lemma specifies conditions under which we can find roots for f(x) modulo pk+m, m ≤ k, when we know a root for f(x) modulo pk. In particular, suppose that
(15)let
(16)then
(17)what if f'(r) is zero
general case when n is composite
quadratic residuosity problem
Discrete Logarithm
The discrete log of g base b, where both g and b are residues modulo n, is an integer k such at bk = g. If n is prime, then the multiplicative group is cyclic and a solution exists if b is not 0 or 1, and g is not 0. 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.
Multiple Equations
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 ni are all pairwise relatively prime:
(18)Moreover, if a and a' are two solutions, then:
(19)The way to find a solution is by repeated application of the extended Euclidean algorithm. Find m1 and m2 such that
(20)Then
(21)will be a solution to the first two equations. These can be replaced by
(22)to get a system of k - 1 equations.