Discrete MathematicsDivisibility, Primes and Greatest Common Divisors5 of 6
Divisibility, Primes and Greatest Common Divisors · 5
GCD, LCM and the Euclidean Algorithm
When we work with two positive whole numbers, we often need the largest building block that fits cleanly inside both of them, or the smallest length that both of them can build together.
1
What GCD and LCM Mean
The greatest common divisor(gcd) of two positive integers is the largest integer that divides both of them with zero remainder, and the least common multiple(lcm) is the smallest positive integer that both of them divide into cleanly. Let's look at what both questions mean physically using strips of length 12 and 18.
What GCD and LCM Mean
Text solution
Split both strips into their largest shared block for the GCDBoth 12 and 18 can be built cleanly out of blocks of length 6, and any larger block leaves a gap in at least one strip.
Line up repeated tiles of both strips for the LCMLaying out a row of 12-tiles beside a row of 18-tiles from the same starting mark, their ends first meet at 36.
3×12=36,2×18=36⟹lcm(12,18)=36
For any two strip lengths, the GCD is the largest block that fits cleanly inside both strips, while the LCM is the first mark out ahead where repeated tiles of both strips meet. And the two answers are linked: 12 and 18 share a block of 6 and their tiles first line up at 36, while 12 and the shorter 15 share only a block of 3 and their tiles don't line up until 60.
12 and 18 share a block of 6 and their tiles first line up at 36, while 12 and the shorter 15 share only a block of 3 and their tiles don't line up until 60.
2
GCD, LCM, and the Product Rule from Prime Factors
Testing block sizes by trial and error only works for tiny numbers. When we have the prime factorizations of two numbers, we can read off both their GCD and their LCM directly from the primes they share. By unique factorization, every integer greater than 1 breaks down into one exact set of prime factors; lining up the prime factors of 12 and 18 shows where 6 and 36 come from and how they are connected.
GCD, LCM, and the Product Rule from Prime Factors
Text solution
Take the shared prime overlap (smaller exponents) for the GCDA number can divide both 12 and 18 only if both have those prime factors to give, so the number with fewer copies of a prime limits how many copies the GCD can have.
Take each prime column once (larger exponents) for the LCMFor both 12 and 18 to divide into a number, it must include every prime factor of each without double-counting their shared overlap.
lcm(12,18)=2×2×3×3=larger exponents22⋅32=36
Divide out the double-counted overlap to get the LCM from the GCDMultiplying a×b includes the shared overlap twice: one copy builds lcm(a,b) and the second copy is gcd(a,b). So dividing one number by the GCD before multiplying by the other gives the LCM right away.
When you use lcm(a,b)=gcd(a,b)a×b by hand, always divide one of the numbers by gcd(a,b) first rather than multiplying a×b into a huge number and doing long division afterward.
In the aligned prime factor rows of a and b, every prime shared by both numbers is counted twice in a×b: one copy goes into lcm(a,b) and the second copy goes into gcd(a,b). So gcd(a,b)×lcm(a,b) always has the exact same prime factors as a×b.
Every shared prime factor goes once to the LCM and once to the GCD, so multiplying the GCD and LCM always uses the exact same prime blocks as multiplying the two numbers.
3
Three Numbers and Why the Product Rule Breaks
What if we want the GCD and LCM of three numbers, such as 12,18, and 30? Lining up prime factor columns still finds the largest block that fits inside all three and the first mark where all three line up, but multiplying gcd(a,b,c)×lcm(a,b,c) no longer equals a×b×c.
Three Numbers and Why the Product Rule Breaks
gcd(a,b,c)×lcm(a,b,c)=?a×b×c
Text solution
Take the three-way overlap for the GCD and each column once for the LCMOnly 2×3 appears in all three prime factor rows, while bringing down every column once gives 180.
121830=2×2×3=2×2×3×3=2×2×3×3×5
⟹gcd(12,18,30)=6,lcm(12,18,30)=2×2×3×3×5=180
Compare gcd×lcm against the three-number productIn 12×18×30, the three-way overlap 6 is counted three times (leaving two extra copies worth 6×6=36, whereas the GCD keeps only one), and in 6,10, and 15, each prime is shared by two rows while the three-way GCD misses two-way overlaps completely.
Prime factors work well when numbers are small or already factored, but factoring large numbers like 10,403 and 7,387 by trial division is painfully slow. We need a way to find gcd(a,b) without ever factoring either number.
By the Division Algorithm, fitting as many copies of b as possible inside a leaves a remainder r smaller than b:
a=qb+r,0≤r<b
Taking copies of 15 off a bar of length 36 shows why the leftover remainder keeps the exact same GCD.
The Idea Behind the Euclidean Algorithm
Text solution
Take copies of 15 from 36 to trade (36,15) for (15,6)Any block d that divides both 36 and 15 cleanly must also divide the leftover remainder 6, and any block that divides 15 and 6 also divides 2×15+6=36.
36=2×15+remainder6⟹gcd(36,15)=gcd(15,6)
Repeat on the smaller pair until the remainder is 0Fitting 6s into 15 leaves 3, and fitting 3s into 6 leaves 0, showing that 3 is the largest shared block.
Geometrically, each remainder step gcd(a,b)=gcd(b,r) fills an a×b rectangle with as many b×b squares as fit and leaves an uncovered b×r strip. The last square that fills a strip with zero remainder has side length gcd(a,b) and tiles the entire rectangle.
Packing each leftover strip with the largest squares that fit shrinks the problem step by step until the final square cleanly tiles the entire rectangle.
5
Proving the Euclidean Algorithm Works
To know that the Euclidean Algorithm works for every pair of positive integers a and b, we need to prove two facts: that replacing (a,b) with (b,r) never changes the GCD, and that repeating the division step must eventually reach a remainder of 0.
Proving the Euclidean Algorithm Works
agcd(a,b)=qb+r=?gcd(b,r)
Text solution
Direction 1 (Every common divisor of a and b also divides r)If d∣a and d∣b, then a=dk and b=dm for some integers k and m, so solving for the remainder r=a−qb shows that d divides r (and so d is a common divisor of b and r).
r=a−qb=dk−q(dm)=d(k−qm)⟹d∣r
Direction 2 (Every common divisor of b and r also divides a)Conversely, if d∣b and d∣r, then b=dm and r=dℓ for some integers m and ℓ, so substituting into a=qb+r shows that d divides a (and so d is a common divisor of a and b).
a=qb+r=q(dm)+dℓ=d(qm+ℓ)⟹d∣a
Why the remainders must hit 0 at gcd(a,b)Because (a,b) and (b,r) have the exact same common divisors, gcd(a,b)=gcd(b,r). Each division step produces a non-negative integer remainder strictly smaller than the divisor before it, so by the Well-Ordering Principle the chain must reach rk+1=0 in at most b steps, leaving the last non-zero remainder rk as the GCD (since 0=0×rk is divisible by rk).
Computing GCD and LCM with the Euclidean Algorithm
Now we can combine the Euclidean Algorithm with the two-number product rule to compute gcd and lcm quickly without factoring: first on a pair of numbers (252 and 105), then on three numbers (252,105, and 60) by pairing them two at a time, and finally on two numbers (43 and 12) that share no prime factors at all.
Computing GCD and LCM with the Euclidean Algorithm
252=?×(105)+?
gcd(252,105)lcm(252,105)=?=?
Text solution
Slide the divisor and remainder left until remainder 0, then use the product ruleFor 252 and 105, each divisor and remainder become the next row's big number and divisor until the remainder hits 0 at 21; dividing 105 by 21 first gives lcm(252,105).
Pair two numbers at a time to handle three numbers without factoringPair the third number 60 with the first pair's GCD (21) to get the three-way GCD, and pair 60 with the first pair's LCM (1,260) to get the three-way LCM.
Recognize relatively prime numbers when the last non-zero remainder is 1Running the division steps on 43 and 12 ends at a last non-zero remainder of 1, meaning they share no prime factors and their LCM is simply their product.
We can also work backwards up those division rows, starting from 1=5−2×(2), to write gcd(a,b) as a combination of a and b (Bézout's Identity).
Key concepts
Keep the two physical pictures straight: gcd(a,b) goes smaller (the largest block that fits inside both a and b), while lcm(a,b) goes bigger (the first mark where repeated tiles of a and b line up). When gcd(a,b)=1, the two numbers share no prime factors and are relatively prime (coprime), even when a number itself isn't prime (such as gcd(43,12)=1).
If the numbers are already prime-factored, don't multiply them out to run long division
Line up the primes and take the smaller exponent on each prime for the GCD and the larger exponent for the LCM (treating any missing prime as exponent 0). For 12=22⋅31 and 18=21⋅32,gcd(12,18)=21⋅31=6 and lcm(12,18)=22⋅32=36.
If the numbers are not factored, run the Euclidean Algorithm and the two-number product rule
Repeatedly divide a=qb+r and replace (a,b) with (b,r) until the remainder hits 0; the last non-zero remainder is gcd(a,b) (for 36=2×15+6,15=2×6+3,6=2×3+0, we get gcd(36,15)=3). Then get the LCM from the two-number product rule by dividing one number by the GCD before multiplying:
gcd(a,b)×lcm(a,b)=a×b⟹lcm(a,b)=(a÷gcd(a,b))×b
For 36 and 15,lcm(36,15)=(15÷3)×36=180.
If there are three numbers, pair them two at a time
Because gcd×lcm=product holds only for two numbers, combine three numbers two at a time:
Let a=24⋅32⋅73 and b=22⋅35⋅5⋅7. Find gcd(a,b) and lcm(a,b) in prime-factored form.
A common mistake is keeping 51 in the GCD to get 22⋅32⋅5⋅7=1,260 because 5 is written in b, or adding exponents in the LCM to get 26⋅37⋅5⋅74; a missing prime has exponent 0, and the LCM takes the larger exponent, not the sum.
Write a and b with all four primes (2,3,5, and 7) lined up: what exponent does 5 have in a, and what exponent does 7 have in b?
Write both numbers with every prime present so no column is skipped:
a=24⋅32⋅50⋅73,b=22⋅35⋅51⋅71
Take the smaller exponent on each prime for the GCD and the larger exponent on each prime for the LCM. (Watch out: a common mistake is keeping 51 in the GCD to get 22⋅32⋅5⋅7=1,260 because 5 is written in b, or adding exponents in the LCM to get 26⋅37⋅5⋅74; a missing prime has exponent 0, and the LCM takes the larger exponent, not the sum.)
gcd(a,b)=22⋅32⋅7=252,lcm(a,b)=24⋅35⋅5⋅73
2
Use the Euclidean Algorithm to find gcd(693,252), and then use the two-number product rule to find lcm(693,252).
On the final line 189=3×63+0, don't take the quotient 3 as the GCD, which would give gcd=3 and lcm=58,212. The GCD is the last non-zero remainder, 63.
Fit as many 252s as possible into 693, then slide the divisor and remainder left; once you have the GCD, which of the two numbers is easier to divide by it before multiplying?
Divide step by step, sliding the divisor and remainder to the left on each new line:
693252189=2×(252)+189=1×(189)+63=3×(63)+0
(Watch out: on the final line 189=3×63+0, don't take the quotient 3 as the GCD, which would give gcd=3 and lcm=58,212. The GCD is the last non-zero remainder, 63.)
gcd(693,252)=63
Divide 252 by 63 before multiplying by 693:
lcm(693,252)=(252÷63)×693=4×693=2,772
3
A rectangular courtyard measures 315 feet by 135 feet. What is the side length of the largest square stone that can tile the entire courtyard cleanly without cutting any stones, and how many of those square stones are needed to cover the courtyard?
A square stone has equal length and width, so its side length must divide both 315 and 135 cleanly; once you find that side length, how many stones fit along each edge of the courtyard?
Run the Euclidean Algorithm on 315 and 135 to find the largest square side length:
315135=2×(135)+45=3×(45)+0
The largest square stone has side length gcd(315,135)=45 feet. Count how many 45-foot stones fit along the length and along the width, then multiply the two edge counts. (Watch out: dividing the area 315×135=42,525 by a single 45 instead of by the stone's area 45×45 gives 945 stones, and adding the edge counts 7+3 instead of multiplying gives 10.)
(315÷45)×(135÷45)=7×3=21
4
Without factoring into primes, find gcd(168,126,105) and lcm(168,126,105) by pairing the numbers two at a time.
Find both gcd(168,126) and lcm(168,126) first; then what two-number problem gives the three-number GCD, and what two-number problem gives the three-number LCM?
Finally, pair 504 with 105 for the LCM by finding lcm(504,105) using the two-number product rule on 504 and 105.(Watch out: don't divide the three-way product 168×126×105=2,222,640 by the three-way GCD 21, which gives the wrong answer 105,840 because it never divides out the 42 overlap from the first pair.)
Two positive integers a and b satisfy gcd(a,b)=15 and lcm(a,b)=450. (a) If a=90, what is b? (b) How many ordered pairs (a,b) of positive integers satisfy gcd(a,b)=15 and lcm(a,b)=450, and what are all the unordered pairs {a,b}?
For (a), use the two-number product rule; for (b), write 15 and 450 in prime-factored form and check which two exponents a and b must have on each prime 2,3, and 5.
(a) By the two-number product rule, a×b=gcd(a,b)×lcm(a,b)=15×450=6,750, so:
b=6,750÷90=75
(b) Factor the GCD and LCM across all primes that appear in either number:
15=20⋅31⋅51,450=21⋅32⋅52
In the prime factorizations of (a,b), the exponents on 2 must have smaller value 0 and larger value 1, giving (0,1) or (1,0), while the exponents on 3 and on 5 must each have smaller value 1 and larger value 2, giving (1,2) or (2,1) for each. (Watch out: overlooking the prime 2 because it isn't written in 15=3×5 leaves only 2×2=4 ordered pairs and 2 unordered pairs.) With 2 independent choices for each of the 3 primes, there are 2×2×2=8 ordered pairs (a,b), which group into 4 unordered pairs:
{15,450},{30,225},{45,150},{75,90}
6
Prove that for every positive integer n, the integers 8n+3 and 5n+2 are relatively prime, and find lcm(8n+3,5n+2) in terms of n.
Don't stop a line early at remainder n and claim gcd=n, which would give the wrong LCM n40n2+31n+6. Two copies of n still fit inside 2n+1, leaving remainder 1.
Run the Euclidean Algorithm step gcd(a,b)=gcd(b,r) directly on the expressions 8n+3 and 5n+2 to shrink the coefficient of n at each step until n cancels out of the remainder.
For any positive integer n, apply the Euclidean Algorithm step repeatedly:
(Watch out: don't stop a line early at remainder n and claim gcd=n, which would give the wrong LCM n40n2+31n+6. Two copies of n still fit inside 2n+1, leaving remainder 1.)