← Math & Numbers · guided lesson

Math & Number Theory

1 / 18 · story

the story

Euclid's algorithm (gcd and lcm)

Every tool here exists because something was too slow or broke without it. Here is what.

c. 300 BCE · Euclid of Alexandria (Elements, Book VII); the method is probably older

Euclid's Elements (c. 300 BCE), Book VII, Propositions 1–2, finds the "greatest common measure" of two numbers by repeatedly taking the smaller from the larger. Historians think Euclid collected the method rather than invented it. In 1844 Gabriel Lamé proved it never needs more than 5 × (digits of the smaller number) division steps, a result often called the start of computational complexity theory. Knuth calls it the oldest nontrivial algorithm that is still in use.

the problem it solved

Find the largest number that divides two numbers exactly — without listing all their divisors.

why it matters: without it

Exact fractions would need slow divisor searches, and RSA key setup (which needs a modular inverse) would lose its fast path.

sources: Euclid's Elements, Book VII, Proposition 2 (D. E. Joyce, Clark University) ↗ · Euclidean algorithm — history and Lamé's bound ↗ · D. E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, §4.5.2 ↗

also in this chapter: Sieve of Eratosthenes · Modular arithmetic (and why 10⁹+7) · Fast power (binary exponentiation) · Combinations nCr and Pascal's triangle (Meru-prastāra) · Place-value digits (% 10 and / 10) · Weighted random pick (prefix sums + binary search)