Let . Two integers are congruent modulo , written , if — equivalently, if and have the same remainder in the Euclidean division by .
Mathematics · Glossary
What is Congruence?
For : when . This is an equivalence relation compatible with addition and multiplication: if and (mod ), then , , and for .
Examples
Example 6.19 (Casting out nines)
Compatibility with and is a checking device as old as commerce. Since , every integer is congruent mod to its digit sum (proved as Exercise 6.2). To check the claim : digit sums give and , so the product must be ; and indeed . The check passes (and the product is in fact correct). Had someone reported , the digit sum would convict them instantly. The test is one-sided — it catches an error unless the error is itself a multiple of — which is exactly the pseudoprime lesson of Example 6.24 in miniature: congruence checks refute, they do not certify.
Example 6.21 (Inverting modulo )
Since , the class of is invertible mod . Extended Euclid:
then backwards:
Hence , i.e. ; check: . With the inverse in hand, any congruence is solved in one multiplication: . This mechanical inversion is the workhorse of modular arithmetic — and of the public-key protocols mentioned in Remark 6.27, where the moduli have hundreds of digits but the algorithm is exactly this one.
Example 6.22 (When the coefficient is not invertible)
Solve . Here , so is not invertible mod — but the equation is still tractable. The congruence says ; dividing the whole relation by (divisor of all three ingredients), it is equivalent to , i.e.
Now and (), so : the solutions are — four classes mod , matching the gcd. (Had the right side not been divisible by , say , there would be no solution at all: the left side is always .) General shape: is solvable iff , and then has exactly solution classes — divide everything by the gcd and invert.