GCD and LCM — The Euclidean Algorithm

gcd(a, b) = gcd(b, a mod b), looped until b = 0. Watch the pair shrink, and the rectangle tile with squares whose side is the GCD.

step 0

Geometric view: tile an a × b rectangle

Lay the biggest b × b squares along the rectangle; the leftover strip is a mod b.
b×b squares this step final GCD square leftover (a mod b)

Algebraic view: gcd(a, b) = gcd(b, a mod b)

Press Step to begin. Each step replaces (a, b) with (b, a mod b); the remainder strictly decreases, so we reach b = 0 in O(log min(a, b)) steps.

Try these inputs

Self-contained visualization. The last non-zero second argument is gcd(a, b); the rectangle tiles exactly with squares of that side. Then lcm(a, b) = a / gcd(a, b) * b (divide before multiply to avoid overflow). See junior.md and professional.md for the proof that the substitution a → a mod b preserves the set of common divisors.