Mathematics · Glossary

What is Congruence?

Definition 29.4 High School Mathematics · Chapter 29 — Arithmetic

Let nNn \in \N^*. Two integers a,ba, b are congruent modulo nn, written ab(modn)a \equiv b \pmod n, if n(ab)n \mid (a - b) — equivalently, if aa and bb have the same remainder in the Euclidean division by nn.

Read in context →
Definition 6.18 University Mathematics — Year 1 · Chapter 6 — Integer Arithmetic

For nNn \in \N^*: ab(modn)a \equiv b \pmod n when nabn \mid a - b. This is an equivalence relation compatible with addition and multiplication: if aba \equiv b and aba' \equiv b' (mod nn), then a+ab+ba + a' \equiv b + b', aabbaa' \equiv bb', and akbka^k \equiv b^k for kNk \in \N.

Examples

Example 6.19 (Casting out nines)

Compatibility with ++ and ×\times is a checking device as old as commerce. Since 101(mod9)10 \equiv 1 \pmod 9, every integer is congruent mod 99 to its digit sum (proved as Exercise 6.2). To check the claim 1234×567=6996781234 \times 567 = 699\,678: digit sums give 123411234 \equiv 1 and 567180(mod9)567 \equiv 18 \equiv 0 \pmod 9, so the product must be 1×0=0\equiv 1 \times 0 = 0; and indeed 6+9+9+6+7+8=4506 + 9 + 9 + 6 + 7 + 8 = 45 \equiv 0. The check passes (and the product is in fact correct). Had someone reported 699478699\,478, the digit sum 437≢043 \equiv 7 \not\equiv 0 would convict them instantly. The test is one-sided — it catches an error unless the error is itself a multiple of 99 — which is exactly the pseudoprime lesson of Example 6.24 in miniature: congruence checks refute, they do not certify.

Example 6.21 (Inverting 77 modulo 2626)

Since gcd(7,26)=1\gcd(7, 26) = 1, the class of 77 is invertible mod 2626. Extended Euclid:

26=3×7+5,7=1×5+2,5=2×2+1,26 = 3 \times 7 + 5, \qquad 7 = 1 \times 5 + 2, \qquad 5 = 2 \times 2 + 1 ,

then backwards:

1=52×2=52(75)=3×52×7=3(263×7)2×7=3×2611×7.1 = 5 - 2 \times 2 = 5 - 2(7 - 5) = 3 \times 5 - 2 \times 7 = 3(26 - 3 \times 7) - 2 \times 7 = 3 \times 26 - 11 \times 7 .

Hence 7×(11)1(mod26)7 \times (-11) \equiv 1 \pmod{26}, i.e. 711115(mod26)7^{-1} \equiv -11 \equiv 15 \pmod{26}; check: 7×15=105=4×26+17 \times 15 = 105 = 4 \times 26 + 1. With the inverse in hand, any congruence 7xc(mod26)7x \equiv c \pmod{26} is solved in one multiplication: x15cx \equiv 15c. 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 12x8(mod20)12x \equiv 8 \pmod{20}. Here gcd(12,20)=4\gcd(12, 20) = 4, so 1212 is not invertible mod 2020 — but the equation is still tractable. The congruence says 2012x820 \mid 12x - 8; dividing the whole relation by 44 (divisor of all three ingredients), it is equivalent to 53x25 \mid 3x - 2, i.e.

3x2(mod5).3x \equiv 2 \pmod 5 .

Now gcd(3,5)=1\gcd(3, 5) = 1 and 312(mod5)3^{-1} \equiv 2 \pmod 5 (3×2=613 \times 2 = 6 \equiv 1), so x4(mod5)x \equiv 4 \pmod 5: the solutions are x4,9,14,19(mod20)x \equiv 4, 9, 14, 19 \pmod{20}four classes mod 2020, matching the gcd. (Had the right side not been divisible by 44, say 12x6(mod20)12x \equiv 6 \pmod{20}, there would be no solution at all: the left side is always 0(mod4)\equiv 0 \pmod 4.) General shape: axb(modn)ax \equiv b \pmod n is solvable iff gcd(a,n)b\gcd(a, n) \mid b, and then has exactly gcd(a,n)\gcd(a, n) solution classes — divide everything by the gcd and invert.

Read in context →