MathLabs

Grade 6

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 4848 cm and 1818 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\gcd(48,18)=6 cm, the greatest common divisor. Conversely, if one beacon flashes every 4848 seconds and another every 1818 seconds, the first positive time they flash together again is lcm⁡(48,18)=144\operatorname{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(n+5)\times 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)\gcd(n+5, n).

SchoolDefinitions, Euclidean algorithm, and the product identity

Definition: Greatest common divisor and least common multiple

For positive integers a,ba,b, the greatest common divisor gcd⁡(a,b)\gcd(a,b) is the largest positive integer dd satisfying d∣ad\mid a and d∣bd\mid b (when gcd⁡(a,b)=1\gcd(a,b)=1, we say aa and bb are coprime). The least common multiple lcm⁡(a,b)\operatorname{lcm}(a,b) is the smallest positive integer mm satisfying a∣ma\mid m and b∣mb\mid m.

gcd⁡(a,b)=gcd⁡(b,r)(a=bq+r, 0≤r<b)\gcd(a,b) = \gcd(b,r) \qquad (a = bq + r,\ 0 \le r < b)

This is the key step of Euclid's algorithm: dividing aa by bb to get a=bq+r, 0≤r<ba=bq+r,\ 0\le r<b preserves the greatest common divisor via gcd⁡(a,b)=gcd⁡(b,r)\gcd(a,b)=\gcd(b,r). Repeating until the remainder reaches 00 finds gcd⁡(a,b)\gcd(a,b) without ever factoring aa or bb.

gcd⁡(a,b)⋅lcm⁡(a,b)=ab(a,b>0)\gcd(a,b) \cdot \operatorname{lcm}(a,b) = a b \qquad (a,b > 0)

Once gcd⁡(a,b)\gcd(a,b) is known, lcm⁡(a,b)\operatorname{lcm}(a,b) comes immediately from the product identity gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b)\cdot\operatorname{lcm}(a,b)=ab: divide the product abab by gcd⁡(a,b)\gcd(a,b).

Examples of gcd, lcm, and the product identity
Pair (a,b)(a,b)gcd⁡(a,b)\gcd(a,b)lcm⁡(a,b)\operatorname{lcm}(a,b)Product check
(8,12)(8,12)4424244×24=8×12=964\times24=8\times12=96
(9,16)(9,16)111441441×144=9×16=1441\times144=9\times16=144
(15,25)(15,25)5575755×75=15×25=3755\times75=15\times25=375
(48,18)(48,18)661441446×144=48×18=8646\times144=48\times18=864

UndergraduateWhy Euclid's algorithm and the product formula work

For integers a≥b>0a\ge b>0 with a=bq+r, 0≤r<ba=bq+r,\ 0\le r<b, the set of common divisors of aa and bb equals the set of common divisors of bb and rr; hence gcd⁡(a,b)=gcd⁡(b,r)\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)\gcd(a,b).

Why is it true?

Subtracting a multiple of bb from aa cannot create or destroy a shared divisor with bb: anything that measures both aa and bb must also measure the leftover r=a−bqr=a-bq, and vice versa.

Proof

Step 1 (Same common divisors). Let dd be any integer dividing both aa and bb, so a=dxa=dx and b=dyb=dy for integers x,yx,y. Then r=a−bq=dx−dyq=d(x−yq)r=a-bq=dx-dyq=d(x-yq), so d∣rd\mid r, meaning dd divides both bb and rr. Conversely, if dd divides both bb and rr, say b=dyb=dy and r=dzr=dz, then a=bq+r=dyq+dz=d(yq+z)a=bq+r=dyq+dz=d(yq+z), so d∣ad\mid a, meaning dd divides both aa and bb.

Step 2 (Equality of greatest common divisors). Because the pairs (a,b)(a,b) and (b,r)(b,r) have the exact same set of common divisors, they have the exact same maximum element: gcd⁡(a,b)=gcd⁡(b,r)\gcd(a,b)=\gcd(b,r).

Step 3 (Finite termination). Each division step produces a remainder satisfying 0≤r<b0\le r<b, so the sequence of second entries b>r1>r2>⋯≥0b > r_1 > r_2 > \cdots \ge 0 is a strictly decreasing sequence of non-negative integers. Such a sequence can have at most bb steps before reaching 00; at the step gcd⁡(rk−1,rk)=gcd⁡(rk,0)=rk\gcd(r_{k-1},r_k)=\gcd(r_k,0)=r_k, the last nonzero remainder rkr_k is gcd⁡(a,b)\gcd(a,b).

For any two positive integers aa and bb, gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b)\cdot\operatorname{lcm}(a,b)=ab.

Why is it true?

For each prime pp, gcd⁡(a,b)\gcd(a,b) takes the smaller exponent of pp in a,ba,b while lcm⁡(a,b)\operatorname{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 aa and bb over all primes pp: a=∏ppepa=\prod_p p^{e_p} and b=∏ppfpb=\prod_p p^{f_p}, where ep,fp≥0e_p,f_p\ge0 and only finitely many exponents are nonzero.

Step 2. A positive integer d=∏ppcpd=\prod_p p^{c_p} divides both aa and bb iff cp≤epc_p\le e_p and cp≤fpc_p\le f_p for every pp, so the largest such divisor chooses cp=min⁡(ep,fp)c_p=\min(e_p,f_p): gcd⁡(a,b)=∏ppmin⁡(ep,fp)\gcd(a,b)=\prod_p p^{\min(e_p,f_p)}. Dual reasoning for common multiples chooses the smallest exponent at least as large as both, giving lcm⁡(a,b)=∏ppmax⁡(ep,fp)\operatorname{lcm}(a,b)=\prod_p p^{\max(e_p,f_p)}.

Step 3. For any two real numbers, min⁡(ep,fp)+max⁡(ep,fp)=ep+fp\min(e_p,f_p)+\max(e_p,f_p)=e_p+f_p. 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\gcd(a,b)\cdot\operatorname{lcm}(a,b)=\prod_p p^{\min(e_p,f_p)+\max(e_p,f_p)}=\prod_p p^{e_p+f_p}=\left(\prod_p p^{e_p}\right)\left(\prod_p p^{f_p}\right)=ab.

UndergraduateReal-World Applications and Worked Examples

Construction engineers use gcd⁡(a,b)\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)\operatorname{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 4848 m by 1818 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 ss m fits without cutting along both dimensions iff s∣48s\mid48 and s∣18s\mid18, so the largest such ss is gcd⁡(48,18)\gcd(48,18).

Step 2. Run Euclid's algorithm: 48=2×18+1248=2\times18+12, then 18=1×12+618=1\times12+6, then 12=2×6+012=2\times6+0. The last nonzero remainder is 66, so gcd⁡(48,18)=6\gcd(48,18)=6 m.

Step 3. Count the slabs: 48÷6=848\div6=8 slabs along the length and 18÷6=318\div6=3 slabs along the width, requiring 8×3=248\times3=24 slabs in total.

Example: Synchronizing two bus routes

Route A departs the central station every 1212 minutes and Route B departs every 1818 minutes. Both leave together at 08:0008{:}00. After how many minutes will they next depart together, and at what clock time?

Solution

Step 1. Route A departs at multiples of 1212 minutes and Route B at multiples of 1818 minutes, so the first positive simultaneous departure is at lcm⁡(12,18)\operatorname{lcm}(12,18) minutes.

Step 2. Find the gcd first: 18=1×12+618=1\times12+6 and 12=2×6+012=2\times6+0, giving gcd⁡(12,18)=6\gcd(12,18)=6.

Step 3. Apply the product identity: lcm⁡(12,18)=12×186=36\operatorname{lcm}(12,18)=\dfrac{12\times18}{6}=36 minutes. Adding 3636 minutes to 08:0008{:}00 gives the next simultaneous departure at 08:3608{:}36.

Using the first step of Euclid's algorithm on (48,18)(48,18), namely 48=2×18+1248=2\times18+12, which gcd equality holds?

Two positive integers a,ba,b satisfy ab=180ab=180 and gcd⁡(a,b)=6\gcd(a,b)=6. What is lcm⁡(a,b)\operatorname{lcm}(a,b)?

Which of the following pairs of numbers is coprime (gcd⁡(a,b)=1\gcd(a,b)=1)?

Two gears with 1616 teeth and 2020 teeth mesh with a marked tooth pair aligned. After how many tooth advances does the same marked pair first align again?

References

  1. David M. Burton (2010). Elementary Number Theory
  2. John H. Conway, Richard K. Guy (1996). The Book of Numbers · DOI:10.1007/978-1-4612-4072-3