8.3 Modular Arithmetic, Inverses, and the Chinese Remainder Theorem
Section 8.2 repeatedly used remainders to shrink a gcd problem. Modular arithmetic changes the viewpoint: instead of treating a remainder as a temporary by-product, we group all integers that have the same remainder.
This produces a finite arithmetic system from infinitely many integers.
Congruence means equal remainder class
Fix a positive integer , called the modulus. For integers and , we write
and say “ is congruent to modulo ” if
Equivalently, and leave the same remainder when divided by .
Example modulo
Because
we have
Both numbers have remainder after division by .
Negative integers also belong to remainder classes. Since
we have
The symbol is still ordinary equality. Congruence is a different relation: , although .
Residues and residue classes
Every integer is congruent modulo to exactly one member of
These standard representatives are called residues modulo .
For modulus , the residue class of contains
because neighboring entries differ by .
Congruence is an equivalence relation from Chapter 4:
- ;
- if , then ;
- if and , then .
Therefore congruence partitions into disjoint residue classes.
Addition and multiplication respect congruence
Suppose
Then
and
For addition,
which is divisible by .
For multiplication, rewrite the difference as
Both terms are divisible by , so their sum is divisible by .
These rules let us reduce before or after an operation.
Example: reducing a large product
Compute .
First reduce each factor:
Then
No large multiplication was necessary.
Powers can be reduced repeatedly
Congruence multiplication can be applied again and again. For example,
so
For very large exponents, repeated squaring reduces both the base and each intermediate square. Section 8.4 will use this technique for RSA.
Rotate integers around a residue clock, then compose addition and multiplication moves on two synchronized rings. Dragging through negative and oversized values preserves their class trail, while a collision detector explains congruence through both equal remainders and divisible differences.
A modular inverse undoes multiplication
For ordinary nonzero rational numbers, multiplication by is undone by multiplying by . Inside modular arithmetic, division is possible only when a suitable residue exists.
An integer is a multiplicative inverse of modulo if
We may write
The notation here means a modular inverse, not the real-number fraction .
When does an inverse exist?
The inverse exists exactly when
Integers with gcd are called coprime or relatively prime.
If , Bézout's identity provides integers such that
Reducing modulo removes the multiple and gives
So the Bézout coefficient of is an inverse.
Conversely, if , then is divisible by . Thus
for some integer , forcing every common divisor of to divide . Hence their gcd is .
Finding an inverse with the extended Euclidean algorithm
Find the inverse of modulo .
Euclid's algorithm gives
Back-substitute:
Therefore
The standard nonnegative representative of is , so
Check:
Solving a linear congruence
To solve
multiply both sides by the inverse :
This resembles ordinary division, but the inverse exists because and are coprime.
More generally, has a solution exactly when
This is the linear-combination criterion from Section 8.2 in modular form.
Combining remainder conditions
Suppose a number must satisfy several clocks at once:
and
The moduli are pairwise coprime: every two distinct moduli have gcd .
The Chinese Remainder Theorem (CRT) states that a system
with pairwise-coprime positive moduli has exactly one solution modulo
“Exactly one modulo ” means that all integer solutions belong to one residue class .
Constructing the CRT solution
For each equation, define
Because the moduli are pairwise coprime,
so has an inverse modulo :
Then
Each product behaves like a selector: it is on clock and on every other clock because it contains those other moduli as factors.
Worked CRT example
Here
For modulus , and . Its inverse is , because .
For modulus , , so its inverse is .
For modulus , , so its inverse is .
Therefore
Check all three clocks:
Set residue targets on two or three independent cyclic beacons, then sweep one shared integer timeline until their signals align. Switch between search mode and constructive selector mode to see both why the solution repeats every product of coprime moduli and how CRT builds it directly.
Section bridge
We can now multiply and exponentiate in a finite residue system, find inverses through Bézout coefficients, and combine congruences through CRT. Section 8.4 assembles exactly these tools into a small RSA public-key system.