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, , is the largest number dividing both and exactly — it captures what two numbers have "in common" as building blocks. The least common multiple, , is the smallest number both and divide into exactly — it captures when two repeating cycles next align. They're linked by one identity worth memorizing:
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 or directly (via Euclid's algorithm, which is fast even for large numbers) and can get the other for free by dividing by it.
Worked example 1: the lighthouses
Find using Euclid's algorithm: , then — the last nonzero remainder is 6, so . By the identity, . So the lighthouses next flash together after 72 seconds — verified by checking that 72 is a multiple of both 18 () and 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 . Euclid's algorithm: , then , then — so . The largest tile is feet, giving 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.
— 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 and every 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 whenever the numbers don't share an "obvious" factor. That's only true when (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