Modular Arithmetic
Modular arithmetic deals with remainders after division, focusing on what's left over when one integer is divided by another. The notation a mod n represents the remainder when a is divided by n, always yielding a value between 0 and n-1. Two numbers are congruent modulo n if they leave the same remainder when divided by n, written as a ≡ b (mod n).
Why it matters
Modular arithmetic powers modern cryptography, with RSA encryption relying on calculations modulo large prime numbers exceeding 1024 bits. Computer hash functions use modular operations to distribute data evenly across memory locations, while error-correcting codes in CDs and digital communications depend on arithmetic modulo specific numbers. Clock calculations naturally use modular arithmetic — adding 8 hours to 7 PM gives 3 AM because (7 + 8) mod 12 = 3. Credit card validation employs the Luhn algorithm, which uses modular arithmetic to detect typing errors in 16-digit card numbers. In advanced mathematics, modular arithmetic appears in number theory, abstract algebra, and discrete mathematics courses, providing the foundation for understanding cyclic groups and finite fields used in coding theory.
How to solve modular arithmetic
Modular Arithmetic (Congruences)
- a mod n is the remainder when a is divided by n: a = n·q + r with 0 ≤ r < n.
- a ≡ b (mod n) means (a − b) is a multiple of n — equivalently, a and b leave the same remainder when divided by n.
- Addition and multiplication respect congruence: (a + b) mod n and (a · b) mod n can be computed by reducing each part mod n first.
- To solve ax ≡ b (mod n) when gcd(a, n) = 1, multiply both sides by the modular inverse of a.
Example: 17 mod 5 = 2 (since 17 = 3·5 + 2). And 17 ≡ 2 (mod 5) because 17 − 2 = 15 is a multiple of 5.
Worked examples
Compute 36 mod 3.
Answer: 0
- Find the largest multiple of 3 that is ≤ 36 → 3 × 12 = 36 — We want the biggest number of the form 3·k that does not exceed 36. Dividing, 36 ÷ 3 = 12 with something left over, so 3·12 = 36.
- Subtract to find the remainder → 36 − 36 = 0 — The remainder is what is left after removing the multiple: 36 − 36 = 0.
- State the answer → 36 mod 3 = 0 — So 36 mod 3 = 0 (since 36 = 3·12 + 0).
Is 17 ≡ 13 (mod 4)?
Answer: yes
- Compute the difference a − b → 17 − 13 = 4 — Two numbers are congruent mod n exactly when their difference is a multiple of n. So we compute 17 − 13 = 4.
- Check whether 4 is divisible by 4 → 4 = 4 · 1 — Dividing: 4 ÷ 4 = 1 remainder 0. The remainder is 0, so the difference is a multiple of n.
- Answer → Yes — 17 ≡ 13 (mod 4) — Yes: since 4 is a multiple of 4, we have 17 ≡ 13 (mod 4).
Compute (2 × 2) mod 13.
Answer: 4
- Compute the product first → 2 × 2 = 4 — Do the arithmetic inside first: 2 × 2 = 4.
- Reduce 4 modulo 13 → 4 = 13 · 0 + 4 — Divide 4 by 13: 4 ÷ 13 = 0 remainder 4. The remainder is what we keep.
- State the answer → (2 × 2) mod 13 = 4 — So (2 × 2) mod 13 = 4 mod 13 = 4.
Common mistakes
- Confusing 23 mod 5 with 23 ÷ 5, writing 4.6 instead of the correct remainder 3
- Computing (7 × 8) mod 6 as 56 mod 6 = 2, but forgetting that 7 mod 6 = 1 and 8 mod 6 = 2, so the answer is (1 × 2) mod 6 = 2
- Writing 15 ≡ 7 (mod 4) as false because 15 - 7 = 8, but failing to recognize that 8 is divisible by 4, making the congruence true