Quant Memo
Core

GCD and LCM Puzzles

Greatest common divisor and least common multiple aren't just definitions to recall — they're the fast route through a whole family of scheduling, tiling, and fraction-simplifying puzzles, especially once you know the identity linking them to the numbers' product.

Two lighthouses flash every 18 seconds and every 24 seconds respectively, both flashing together at time zero. How many seconds until they next flash together? This is a least-common-multiple question in disguise, and it's typical of a puzzle family — scheduling, tiling, fraction problems — that becomes fast and mechanical once you recognize the GCD/LCM structure and use the identity connecting them, rather than listing out multiples by hand.

The core idea: GCD measures shared structure, LCM measures shared timing

The greatest common divisor, gcd(a,b)\gcd(a,b), is the largest number dividing both aa and bb exactly — it captures what two numbers have "in common" as building blocks. The least common multiple, lcm(a,b)\text{lcm}(a,b), is the smallest number both aa and bb divide into exactly — it captures when two repeating cycles next align. They're linked by one identity worth memorizing:

gcd(a,b)×lcm(a,b)=a×b.\gcd(a,b) \times \text{lcm}(a,b) = a \times b .

In plain English: the product of the two numbers splits exactly into "what they share" times "how far apart their cycles need to run before syncing up again." This means you only ever need to compute one of gcd\gcd or lcm\text{lcm} directly (via Euclid's algorithm, which is fast even for large numbers) and can get the other for free by dividing a×ba \times b by it.

Worked example 1: the lighthouses

Find gcd(18,24)\gcd(18, 24) using Euclid's algorithm: 24=1×18+624 = 1 \times 18 + 6, then 18=3×6+018 = 3 \times 6 + 0 — the last nonzero remainder is 6, so gcd(18,24)=6\gcd(18,24) = 6. By the identity, lcm(18,24)=18×246=4326=72\text{lcm}(18,24) = \dfrac{18 \times 24}{6} = \dfrac{432}{6} = 72. So the lighthouses next flash together after 72 seconds — verified by checking that 72 is a multiple of both 18 (72=4×1872 = 4 \times 18) and 24 (72=3×2472 = 3 \times 24), and it's the smallest such number since 6 is the largest shared factor.

Worked example 2: a tiling puzzle using GCD

A rectangular floor measures 42 feet by 30 feet, and you want to tile it exactly with the largest possible square tiles, no cutting. The largest square that tiles both dimensions evenly has side length gcd(42,30)\gcd(42, 30). Euclid's algorithm: 42=1×30+1242 = 1 \times 30 + 12, then 30=2×12+630 = 2 \times 12 + 6, then 12=2×6+012 = 2 \times 6 + 0 — so gcd(42,30)=6\gcd(42,30) = 6. The largest tile is 6×66 \times 6 feet, giving 426×306=7×5=35\frac{42}{6} \times \frac{30}{6} = 7 \times 5 = 35 tiles exactly, with none cut — a direct physical reading of what "greatest common divisor" means: the biggest unit that both dimensions are whole multiples of.

42 ft 30ft 7 x 5 = 35 tiles of side gcd(42,30) = 6
The largest square tile that fits both dimensions with none cut has side length equal to the greatest common divisor of the two dimensions.

gcd(a,b)×lcm(a,b)=a×b\gcd(a,b) \times \text{lcm}(a,b) = a \times b — compute the GCD quickly with Euclid's algorithm (repeated remainder-taking), then get the LCM for free by division. GCD answers "what's the largest shared unit," LCM answers "when do two cycles next align."

What this means in practice

GCD/LCM reasoning shows up any time an interview question involves repeating cycles (settlement dates, coupon payments, rebalancing schedules that happen every mm and every nn periods) or exact-division constraints (splitting a position into equal lots, tiling, batch sizing). Euclid's algorithm is also worth knowing as a general mental-math speed tool: it's far faster than factoring large numbers to find their GCD, especially under interview time pressure.

A common shortcut mistake is assuming lcm(a,b)=a×b\text{lcm}(a,b) = a \times b whenever the numbers don't share an "obvious" factor. That's only true when gcd(a,b)=1\gcd(a,b)=1 (the numbers are coprime); otherwise it overstates the LCM. Always compute or at least sanity-check the GCD first before assuming the numbers share no common factor.

Related concepts

Practice in interviews

Further reading

  • Niven, Zuckerman & Montgomery, An Introduction to the Theory of Numbers, ch. 1
ShareTwitterLinkedIn