Modular Arithmetic
Modular arithmetic is a system of arithmetic for integers where numbers wrap around when they reach a certain value called the modulus. The expression 'a mod n' represents the remainder when integer a is divided by positive integer n. For example, 17 mod 5 equals 2 because 17 divided by 5 gives quotient 3 with remainder 2.
Why it matters
Modular arithmetic forms the backbone of cryptography and computer security systems that protect online banking and digital communications. Credit card validation algorithms use modular arithmetic to detect typing errors in 16-digit card numbers. Computer programmers rely on modular arithmetic for hash functions and random number generation. In pure mathematics, modular arithmetic appears in number theory and abstract algebra, particularly in studying divisibility patterns and solving Diophantine equations. The concept extends naturally to more advanced topics like group theory and ring theory at university level. Even simple applications like determining which day of the week a future date falls on use modular arithmetic with modulus 7. Clock arithmetic itself demonstrates modular 12 systems in everyday life.
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 25 mod 7.
Answer: 4
- Find the largest multiple of 7 that is ≤ 25 → 7 × 3 = 21 — We want the biggest number of the form 7·k that does not exceed 25. Dividing, 25 ÷ 7 = 3 with something left over, so 7·3 = 21.
- Subtract to find the remainder → 25 − 21 = 4 — The remainder is what is left after removing the multiple: 25 − 21 = 4.
- State the answer → 25 mod 7 = 4 — So 25 mod 7 = 4 (since 25 = 7·3 + 4).
Is 52 ≡ 28 (mod 5)?
Answer: no
- Compute the difference a − b → 52 − 28 = 24 — Two numbers are congruent mod n exactly when their difference is a multiple of n. So we compute 52 − 28 = 24.
- Check whether 24 is divisible by 5 → 24 = 5 · 4 + 4 — Dividing: 24 ÷ 5 = 4 remainder 4. The remainder is 4 ≠ 0, so the difference is not a multiple of n.
- Answer → No — 52 ≢ 28 (mod 5) — No: since 24 is not a multiple of 5, we have 52 ≢ 28 (mod 5).
Compute (30 × 5) mod 9.
Answer: 6
- Compute the product first → 30 × 5 = 150 — Do the arithmetic inside first: 30 × 5 = 150.
- Reduce 150 modulo 9 → 150 = 9 · 16 + 6 — Divide 150 by 9: 150 ÷ 9 = 16 remainder 6. The remainder is what we keep.
- State the answer → (30 × 5) mod 9 = 6 — So (30 × 5) mod 9 = 150 mod 9 = 6.
Common mistakes
- Computing 23 mod 6 as 5 instead of the correct answer 5 by incorrectly thinking 23 ÷ 6 = 4 remainder 1
- Claiming 15 ≡ 8 (mod 6) when actually 15 ≡ 3 (mod 6) and 8 ≡ 2 (mod 6), so they are not congruent
- Calculating (7 + 11) mod 4 as 2 by adding first to get 18, then finding 18 mod 4 = 2, when the correct approach gives the same result but some confuse the order of operations