Category: Number Theory Level: 101
gcd(12, 18) = 6, lcm(12, 18) = 36
List the factors of both numbers and take the biggest one they share. Hop along the multiples of both numbers and take the first place they meet.
12 has 6 factors and 18 has 6. Write them in order, small to big.
12: 1, 2, 3, 4, 6, 12; 18: 1, 2, 3, 6, 9, 18
Both lists contain 1, 2, 3, and 6. The biggest shared factor is 6, the GCD.
common: 1, 2, 3, 6 ⇒ gcd = 6
Now look at multiples. One frog hops 12 at a time, another hops 18 at a time, both starting at 0.
12, 24, 36, 48, 60, 72; 18, 36, 54, 72
Both frogs land on 36 first. That is the smallest common multiple. They meet again at 72, and every 36 after that.
lcm(12, 18) = 36
cd svg-generator python3 -m svgmath render gcd-lcm-lists --out /tmp/gcd-lcm-lists
Source: svgmath/diagrams/gcd_lcm.py