Category: Number Theory Level: 101
gcd(48, 18) = gcd(18, 12) = … = 6
Cut the biggest possible squares off a rectangle, then repeat on the leftover strip. The last square size that fits exactly is the GCD of the two sides.
Find the biggest square tile that covers a 48 × 18 rectangle with no gaps and no cutting. Its side must divide both 48 and 18.
gcd(48, 18) = ?
Squares of side 18 are the biggest that fit. Two fit, and a 12 × 18 strip is left over. Any tile that covers the rectangle also covers that strip.
48 = 2 × 18 + 12
The strip is 12 wide, so cut squares of side 12. One fits and a 12 × 6 strip is left over.
18 = 1 × 12 + 6
Two squares of side 6 fill the last strip exactly. No leftover, so the algorithm stops.
12 = 2 × 6 + 0
Every square in the picture is a whole number of 6 × 6 tiles, so 6 × 6 tiles cover the whole rectangle: 8 across and 3 down. No bigger tile works, so the GCD is 6.
gcd(48, 18) = 6, 8 × 3 = 24 tiles
cd svg-generator python3 -m svgmath render euclidean-algorithm --out /tmp/euclidean-algorithm
Source: svgmath/diagrams/gcd_lcm.py