Euclidean Algorithm
Statement
For any natural numbers and , the greatest common divisor satisfies:
Iterating this recurrence terminates in finitely many steps because the right-hand argument strictly decreases, reaching .
Additionally, the gcd is the largest common divisor: if and then .
Visualization
Step-by-step trace for :
Step Call Quotient Remainder
1 gcd(252, 105) 2 42
2 gcd(105, 42) 2 21
3 gcd( 42, 21) 2 0
4 gcd( 21, 0) — base case: 21
Divisibility lattice (arrows mean "divides"):
1
/ \
3 7
/ \ / \
21 21
\ /
21
|
gcd(252,105) = 21
Check: and , with .
| 252 | 105 | 42 |
| 105 | 42 | 21 |
| 42 | 21 | 0 |
| 21 | 0 | base: 21 |
Proof Sketch
-
Correctness of the recurrence. Any common divisor of and also divides . Conversely, any common divisor of and divides . So the sets of common divisors are identical, hence the greatest is the same.
-
Termination. At each step the pair is replaced by . Since , the first argument strictly decreases until it reaches 0.
-
Base case. by definition — divides and is the largest divisor of .
-
Every common divisor divides the gcd. By induction on the number of steps: once we reach , the claim holds trivially, and each step preserves the set of common divisors.
Connections
The Euclidean algorithm is the computational backbone of Bezout's IdentityBezout's IdentityThe gcd of two integers is always an integer linear combination of those integersRead more →, which shows the gcd is an integer linear combination of its arguments. It underpins the Chinese Remainder TheoremChinese Remainder TheoremSimultaneous congruences with coprime moduli have a unique solution mod their productRead more → (coprimality) and Euler's Totient FunctionEuler's Totient Functionφ(n) counts integers up to n coprime to n, and governs modular exponentiationRead more → (counting units). The Fundamental Theorem of ArithmeticFundamental Theorem of ArithmeticEvery integer greater than 1 has a unique prime factorizationRead more → tells us the gcd can also be read off prime factorisations, but the Euclidean algorithm is far more efficient.
Lean4 Proof
/-- The Euclidean recurrence: `gcd m n = gcd (n % m) m`.
Mathlib calls this `Nat.gcd_rec`. -/
theorem euclidean_rec (m n : ℕ) : Nat.gcd m n = Nat.gcd (n % m) m :=
Nat.gcd_rec m n
/-- The gcd divides both arguments. -/
theorem gcd_divides (m n : ℕ) : Nat.gcd m n ∣ m ∧ Nat.gcd m n ∣ n :=
⟨Nat.gcd_dvd_left m n, Nat.gcd_dvd_right m n⟩
/-- Any common divisor divides the gcd. -/
theorem common_dvd_gcd {m n k : ℕ} (hm : k ∣ m) (hn : k ∣ n) : k ∣ Nat.gcd m n :=
Nat.dvd_gcd hm hnReferenced by
- Polynomial Division AlgorithmRing Theory
- Euclidean DomainRing Theory
- Multiplicative FunctionsNumber Theory
- Bezout's IdentityNumber Theory
- Bezout's IdentityNumber Theory
- Continued FractionsNumber Theory
- Continued FractionsNumber Theory