Enter the world of clock arithmetic: congruences, modular operations, and the Chinese Remainder Theorem
Modular arithmetic is the mathematics of remainders. When we say a ≡ b (mod n), we mean a and b leave the same remainder when divided by n. It's like a clock: after 12 comes 1 again.
Far from being a curiosity, modular arithmetic is the foundation of modern cryptography, computer science, and much of algebraic number theory. The integers modulo n form rich algebraic structures that connect directly to group theory.
Visualize modular arithmetic as positions on a clock face. Addition moves you clockwise, and when you pass the modulus, you wrap back around to 0. Multiplication creates interesting patterns of jumps around the dial.
Positions 0 to 11 around the clock. Blue = operand a, Gold = result. The arc traces b steps clockwise from a.
Modular arithmetic partitions the integers into congruence classes. Every integer belongs to exactly one class mod n. This partition is compatible with addition and multiplication — you can compute with classes instead of individual numbers.
Each integer is colored by its residue class mod 5. Numbers with the same color are congruent.
The multiplication table mod n reveals the algebraic structure. The units (elements with multiplicative inverses) form a group under multiplication — this is (Z/nZ)*, a central object in number theory and a direct connection to Group Theory.
| × | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| 2 | 0 | 2 | 4 | 6 | 1 | 3 | 5 |
| 3 | 0 | 3 | 6 | 2 | 5 | 1 | 4 |
| 4 | 0 | 4 | 1 | 5 | 2 | 6 | 3 |
| 5 | 0 | 5 | 3 | 1 | 6 | 4 | 2 |
| 6 | 0 | 6 | 5 | 4 | 3 | 2 | 1 |
Cell colors use HSL hues proportional to the result value. Filter rows/columns by choosing a highlight mode above.
Given a system of congruences with coprime moduli, there is always a unique solution modulo the product. This ancient result (attributed to Sun Tzu, ~3rd century) is both theoretically deep and computationally essential.
Number line (0–60):
Solutions in range: 8, 23, 38, 53. The pattern repeats every 15 integers.
The CRT guarantees a unique solution modulo the product of pairwise coprime moduli. Highlighted cells on the number line show all solutions in the displayed range.
Computing ab mod m naively requires b multiplications. The repeated squaring algorithm uses the binary expansion of b to do it in only log(b) steps — essential for cryptography where exponents have hundreds of digits.
Repeated squaring computes be mod m in O(log e) multiplications by scanning the binary digits of the exponent from least to most significant.
You now have a solid grasp of modular arithmetic:
Next: We'll discover Fermat's Little Theorem, Euler's totient function, and the fascinating world of multiplicative arithmetic functions.