Greatest common divisor, least common multiple and the Euclidean algorithm
The largest common factor and smallest common multiple of integers, computed efficiently by Euclid's algorithm.
IntuitionBiggest shared piece and earliest shared cycle
Suppose you have two ribbons of lengths 48 cm and 18 cm and want to cut both into equal pieces of the longest possible integer length with nothing left over: that longest length is gcd(48,18)=6 cm, the greatest common divisor. Conversely, if one beacon flashes every 48 seconds and another every 18 seconds, the first positive time they flash together again is lcm(48,18)=144 seconds, the least common multiple.
Directed step graph illustrating the Euclidean algorithm reducing (48,18) to (6,0)
Geometric Euclidean algorithm: tiling an (n+5)×n rectangle with the largest possible squares step by step until the last square tiles the remainder exactly — its side length is gcd(n+5,n).
SchoolDefinitions, Euclidean algorithm, and the product identity
Definition: Greatest common divisor and least common multiple
For positive integers a,b, the greatest common divisorgcd(a,b) is the largest positive integer d satisfying d∣a and d∣b (when gcd(a,b)=1, we say a and b are coprime). The least common multiplelcm(a,b) is the smallest positive integer m satisfying a∣m and b∣m.
gcd(a,b)=gcd(b,r)(a=bq+r,0≤r<b)
This is the key step of Euclid's algorithm: dividing a by b to get a=bq+r,0≤r<b preserves the greatest common divisor via gcd(a,b)=gcd(b,r). Repeating until the remainder reaches 0 finds gcd(a,b) without ever factoring a or b.
gcd(a,b)⋅lcm(a,b)=ab(a,b>0)
Once gcd(a,b) is known, lcm(a,b) comes immediately from the product identitygcd(a,b)⋅lcm(a,b)=ab: divide the product ab by gcd(a,b).
Examples of gcd, lcm, and the product identity
Pair (a,b)
gcd(a,b)
lcm(a,b)
Product check
(8,12)
4
24
4×24=8×12=96
(9,16)
1
144
1×144=9×16=144
(15,25)
5
75
5×75=15×25=375
(48,18)
6
144
6×144=48×18=864
UndergraduateWhy Euclid's algorithm and the product formula work
For integers a≥b>0 with a=bq+r,0≤r<b, the set of common divisors of a and b equals the set of common divisors of b and r; hence gcd(a,b)=gcd(b,r), and repeating the division step terminates in finitely many steps with the last nonzero remainder equal to gcd(a,b).
Why is it true?
Subtracting a multiple of b from a cannot create or destroy a shared divisor with b: anything that measures both a and b must also measure the leftover r=a−bq, and vice versa.
Proof
Step 1 (Same common divisors). Let d be any integer dividing both a and b, so a=dx and b=dy for integers x,y. Then r=a−bq=dx−dyq=d(x−yq), so d∣r, meaning d divides both b and r. Conversely, if d divides both b and r, say b=dy and r=dz, then a=bq+r=dyq+dz=d(yq+z), so d∣a, meaning d divides both a and b.
Step 2 (Equality of greatest common divisors). Because the pairs (a,b) and (b,r) have the exact same set of common divisors, they have the exact same maximum element: gcd(a,b)=gcd(b,r).
Step 3 (Finite termination). Each division step produces a remainder satisfying 0≤r<b, so the sequence of second entries b>r1>r2>⋯≥0 is a strictly decreasing sequence of non-negative integers. Such a sequence can have at most b steps before reaching 0; at the step gcd(rk−1,rk)=gcd(rk,0)=rk, the last nonzero remainder rk is gcd(a,b).
For any two positive integers a and b, gcd(a,b)⋅lcm(a,b)=ab.
Why is it true?
For each prime p, gcd(a,b) takes the smaller exponent of p in a,b while lcm(a,b) takes the larger exponent; adding the smaller and larger of two numbers always gives their sum.
Proof
Step 1. Write the prime factorizations of a and b over all primes p: a=∏ppep and b=∏ppfp, where ep,fp≥0 and only finitely many exponents are nonzero.
Step 2. A positive integer d=∏ppcp divides both a and b iff cp≤ep and cp≤fp for every p, so the largest such divisor chooses cp=min(ep,fp): gcd(a,b)=∏ppmin(ep,fp). Dual reasoning for common multiples chooses the smallest exponent at least as large as both, giving lcm(a,b)=∏ppmax(ep,fp).
Step 3. For any two real numbers, min(ep,fp)+max(ep,fp)=ep+fp. Multiplying the two productsprime-by-prime therefore gives gcd(a,b)⋅lcm(a,b)=∏ppmin(ep,fp)+max(ep,fp)=∏ppep+fp=(∏ppep)(∏ppfp)=ab.
UndergraduateReal-World Applications and Worked Examples
Construction engineers use gcd(a,b) to choose the largest modular square tile or panel that fits a rectangular floor without cutting; transit planners and embedded-systems engineers use lcm(a,b) to find the hyperperiod of periodic tasks or bus schedules; and cryptography runs Euclid's algorithm on thousand-bit integers millions of times per second.
Example: Tiling a courtyard with the largest square slabs
A rectangular courtyard measures 48 m by 18 m. You want to pave it completely with identical square stone slabs of integer side length (in meters), with no cutting. What is the largest slab side length you can use, and how many slabs are needed?
Solution
Step 1. A square slab of side s m fits without cutting along both dimensions iff s∣48 and s∣18, so the largest such s is gcd(48,18).
Step 2. Run Euclid's algorithm: 48=2×18+12, then 18=1×12+6, then 12=2×6+0. The last nonzero remainder is 6, so gcd(48,18)=6 m.
Step 3. Count the slabs: 48÷6=8 slabs along the length and 18÷6=3 slabs along the width, requiring 8×3=24 slabs in total.
Example: Synchronizing two bus routes
Route A departs the central station every 12 minutes and Route B departs every 18 minutes. Both leave together at 08:00. After how many minutes will they next depart together, and at what clock time?
Solution
Step 1. Route A departs at multiples of 12 minutes and Route B at multiples of 18 minutes, so the first positive simultaneous departure is at lcm(12,18) minutes.
Step 2. Find the gcd first: 18=1×12+6 and 12=2×6+0, giving gcd(12,18)=6.
Step 3. Apply the product identity: lcm(12,18)=612×18=36 minutes. Adding 36 minutes to 08:00 gives the next simultaneous departure at 08:36.
Using the first step of Euclid's algorithm on (48,18), namely 48=2×18+12, which gcd equality holds?
Two positive integers a,b satisfy ab=180 and gcd(a,b)=6. What is lcm(a,b)?
Which of the following pairs of numbers is coprime (gcd(a,b)=1)?
Two gears with 16 teeth and 20 teeth mesh with a marked tooth pair aligned. After how many tooth advances does the same marked pair first align again?