Euclid's algorithm

Type two whole numbers and press Step (or Play). The rectangle is a × b. Each step slices off the biggest squares that fit, and the strip left over is the next, smaller rectangle. Watch the division line that appears with each slice: the number of squares is the quotient and the leftover strip is the remainder. The last square that fits with nothing left over is the greatest common divisor.

What's going on

Any square that tiles both the a × b rectangle and the squares you cut off must also tile the leftover strip, because the strip is just the rectangle with some squares removed. So the common divisors of a and b are exactly the common divisors of b and the remainder. The pair gets smaller every step, so the process has to stop, and when the remainder is 0 the number you were dividing by is the gcd.

It is fast. Each two steps at least halve the smaller number, so even numbers with a hundred digits need only a few hundred divisions. This is the oldest algorithm still in daily use: it is how computers reduce fractions and it sits inside the math(s) that keeps web traffic private.

Try 1071 and 462 (the classic), then 610 and 377 (two Fibonacci numbers, the slowest case for their size: every quotient is 1 until the very last), then two numbers with no common factor and see the final square is 1 × 1.

Sheet: Euclid's algorithm.