We say a divides b (written a | b) if there exists an integer k such that b = ak. Modular arithmetic works with remainders: a ≡ b (mod m) means m | (a−b).
12 ≡ 2 (mod 5) because 5 | (12−2)
7 ≡ 1 (mod 3) because 3 | (7−1)
−3 ≡ 2 (mod 5) because 5 | (−3−2) = −5
Modular arithmetic is behind hash tables (index = key mod size), cyclic error-detection codes, and public-key cryptography.
GCD & the Euclidean Algorithm
The greatest common divisor gcd(a,b) is the largest integer dividing both a and b. The Euclidean algorithm computes it efficiently.
The Euclidean algorithm runs in O(log min(a,b)) steps — very efficient even for large integers.
Prime Numbers & Unique Factorization
An integer p ≥ 2 is prime if its only divisors are 1 and itself. The Fundamental Theorem of Arithmetic: every integer ≥ 2 has a unique prime factorization.
360 = 2³ · 3² · 5
1001 = 7 · 11 · 13
Trial division up to √n suffices to test primality.
Modular Inverse & Applications
The modular inverse of a (mod m) is a number a′ such that a · a′ ≡ 1 (mod m). It exists iff gcd(a,m)=1. Used in RSA encryption.
Find the inverse of 3 mod 7: need 3x ≡ 1 (mod 7).
Try x=5: 3·5=15=2·7+1 ⇒ 15 ≡ 1 (mod 7). ✓
So 3−1 ≡ 5 (mod 7).
Practice Problems
1. Compute gcd(252, 105) using the Euclidean algorithm.