Euclidean Algorithm
Greatest common divisors through repeated remainders
Replace a pair without changing its common divisors
The key identity is gcd(a, b) = gcd(b, a mod b). Any number dividing both a and b also divides their remainder, and the converse follows from a = qb + r. Replacing the pair repeatedly makes the second value strictly smaller.
See remainders as leftover rectangles
A geometric interpretation asks for the largest square tile that can cover an a x b rectangle. Cutting as many short-side squares as possible leaves a rectangle whose side is a mod b. Repeating the tiling performs the same recurrence as the arithmetic algorithm.
The player computes gcd(30, 18). Amber outlines squares cut in the current division step, while the dashed rectangle is the remainder still to tile. The smallest final square has side 6.
Find gcd(30, 18) by repeatedly cutting the largest possible squares from a 30 x 18 rectangle.
Logarithmic convergence
The remainder sequence reaches zero in O(log min(a, b)) steps and needs O(1) iterative space. Consecutive Fibonacci numbers produce the classic worst-case sequence because their remainders shrink as slowly as possible.
ax + by = gcd(a, b), which enables modular inverses. Start the number-theory path with batch prime generation in the Sieve of Eratosthenes.