Discrete MathematicsDivisibility, Primes and Greatest Common Divisors6 of 6
Divisibility, Primes and Greatest Common Divisors · 6
Bezout's Identity and the Extended Euclidean Algorithm
We know how to find the greatest common divisor of two integers, and now we want to know which numbers we can build by adding and subtracting multiples of them.
1
Bézout's Identity
Bézout's Identity says that if you move forward and backward on a number line using two step sizes a and b, the smallest positive number you can land on is their greatest common divisor, gcd(a,b).
Let's see why combining steps of 15 and 6 can land on gcd(15,6)=3 and every multiple of 3, why that smallest positive step must always equal gcd(a,b), and how that tells us whether an equation like 15x+6y=12 has integer solutions.
Bézout's Identity
Because 15 and 6 are both built out of blocks of 3, every combination 15x+6y lands on a multiple of 3=gcd(15,6) and leaves the numbers between them unreachable.
Because 15 and 6 are both built from blocks of 3, combining steps of 15 and 6 can land on every multiple of 3 and never between them.
For any integers a and b (not both zero), there exist integers x and y such that
integer combination of a and bax+by=gcd(a,b)
Because every combination of a and b is a multiple of gcd(a,b), a target integer c is reachable if and only if gcd(a,b) divides c:
ax+by=c has integer solutions x,y⟺gcd(a,b)∣c
Here is how we use that to solve 15x+6y=12 (and why 15x+6y=10 has no integer solution).
Text solution
Check whether gcd(15,6) divides the right-hand sideSince gcd(15,6)=3 divides 12, the equation 15x+6y=12 has integer solutions, whereas 15x+6y=10 has none because 3∤10.
gcd(15,6)=3and3∣12
Write gcd(15,6)=3 as a combination of 15 and 6One step of 15 forward minus two steps of 6 lands on 3.
1(15)−2(6)=3
Multiply the step counts by 312=4 to reach 12Multiplying the whole equation by 4 turns the right-hand side from 3 into 12.
4⋅1(15)−4⋅2(6)4(15)−8(6)=4⋅3=12
So x=4 steps of 15 forward and y=−8 (meaning 8 steps of 6 backward) land on 12.
2
The Extended Euclidean Algorithm
Now we want to find integers x and y that solve
41x+15y=gcd(41,15)
For small numbers like 15 and 6, we could spot 1(15)−2(6)=3 right away, but for 41 and 15 we need a step-by-step method. Remember that the Euclidean Algorithm finds gcd(41,15) by dividing and taking remainders until we reach 0, since each remainder step r=a−qb keeps the exact same common divisors. By isolating those remainders and substituting them in reverse, we can build gcd(41,15) out of 41 and 15.
The Extended Euclidean Algorithm
41x+15y=gcd(41,15)
x=?,y=?
Here are the steps to solve 41x+15y=gcd(41,15) by back-substitution.
Text solution
Divide repeatedly to find the remainders and the GCDRun the Euclidean Algorithm until the remainder is 0; the last non-zero remainder is gcd(41,15)=1.
Isolate each non-zero remainder in unopened boxesRewrite the first four equations with the remainders on the left, keeping [41],[15],[11],[4], and [3] in boxes so they never get multiplied out.
Back-substitute from the bottom equation and group matching boxes after every stepStart with 1=[4]−1[3] and replace the smallest box using the line above it, combining matching boxes before substituting the next one.
So gcd(41,15)=1 with x=−4 and y=11, which you can check right away since −4(41)+11(15)=−164+165=1. You can also work from the top down by substituting each remainder's combination of [41] and [15] into the next line ([4]=−1[41]+3[15], then [3]=3[41]−8[15], then 1=−4[41]+11[15]), which lets you check your arithmetic at every step.
3
Finding All Integer Solutions
Once we have one integer solution (x0,y0)=(4,−8) to
15x+6y=12
we want to find every other pair of integers (x,y) that also solves the equation. To stay at 12 while changing the step counts, any extra forward steps of 15 and backward steps of 6 must cancel each other out to 0.
Finding All Integer Solutions
Shifting the turnaround point by lcm(15,6)=30 adds 2 forward steps of 15 and 5 backward steps of 6, which cancel, so the path still lands on 12, giving a new integer solution (4+2k,−8−5k) at every multiple of 30 and nowhere between them.
Every 30-unit shift of the turnaround point adds or removes 2 steps of 15 and 5 steps of 6, which cancel, so the path still lands on 12.
If (x0,y0) is one integer solution to ax+by=c and d=gcd(a,b), then all integer solutions come from trading db steps of a against da steps of b:
xy=x0+steps of a in trade(db)k,=y0−steps of b in trade(da)k(for any integer k)
Here is how we build all the solutions for 15x+6y=12 from (x0,y0)=(4,−8).
Text solution
Divide the two step sizes by d=gcd(15,6)=3 to find the smallest zero-sum tradeDividing by 3 gives the smallest step counts of 15 and 6 that cover the same distance lcm(15,6)=30.
dbda2(15)−5(6)=36=2(steps of 15)=315=5(steps of 6)=30−30=0
Add k zero-sum trades to the starting solution (4,−8)Adding 2k steps of 15 and subtracting 5k steps of 6 leaves the total unchanged at 12 for every integer k.
x=4+2k,y=−8−5k(for any integer k)
Every integer k gives an integer solution. For instance, k=1 gives x=6,y=−13, where 6(15)−13(6)=90−78=12. In the same way, our solution (−4,11) to 41x+15y=1 (where d=1) gives all solutions x=−4+15k and y=11−41k, so choosing k=1 immediately gives the smallest positive x solution, x=11 and y=−30.
4
Bézout's Identity in Proofs and Euclid's Lemma
When two integers a and b share no common factors (gcd(a,b)=1), Bézout's Identity turns that divisibility fact into an equation we can use inside a proof. In particular, it lets us prove Euclid's Lemma: if gcd(a,b)=1 and a∣bc, then a∣c.
Bézout's Identity in Proofs and Euclid's Lemma
gcd(a,b)a∣bc=1⟹?a∣c
Because 1 is the only positive integer that divides 1, Bézout's Identity works in both directions when the right-hand side is 1:
gcd(a,b)=1⟺ax+by=1 for some integers x,y
Be careful when the right-hand side is larger than 1: finding a combination ax+by=c only proves that gcd(a,b) divides c, not that gcd(a,b)=c. For example, 1(15)−1(6)=9 shows that gcd(15,6)∣9, even though gcd(15,6)=3=9. Only when the combination equals 1 does gcd(a,b)∣1 force gcd(a,b)=1. That makes proving gcd(n+1,n)=1 for any integer n a one-line calculation, since x=1 and y=−1 cancel n and leave 1:
1(n+1)−1(n)=1⟹gcd(n+1,n)=1
In the reverse direction, starting from gcd(a,b)=1 gives a three-step proof of Euclid's Lemma:
Euclid’s Lemma: If gcd(a,b)=1 and a∣bc, then a∣c.
Text solution
Write gcd(a,b)=1 as a Bézout equationSince gcd(a,b)=1, there exist integers x and y that combine a and b to equal 1.
ax+by=1
Multiply both sides by c to isolate c on the rightMultiplying the whole equation by c puts our target c alone on the right and creates bc on the left.
acx+bcy=c
Factor a out of both terms on the leftSince a∣bc, we can write bc=ak for some integer k, making both terms on the left multiples of a.
multiple of aa(cx)+multiple of a(bc)ya(cx)+(ak)ya(cx+ky)=c=c=c
Since cx+ky is an integer, a∣c.
Key concepts
Everything here comes down to whether and how a target number c can be built from steps of size a and b:
Check solvability before computing
An equation ax+by=c has integer solutions if and only if d=gcd(a,b) divides c. Always check d∣c first. If d∤c, stop immediately because no integer solution exists (for 15x+6y=10,gcd(15,6)=3∤10, so there is nothing to solve).
Find one starting solution (x0,y0)
First solve ax+by=d, and then multiply both step counts by dc. Don't run the Extended Euclidean Algorithm when the numbers are small enough to spot a combination right away (1(15)−2(6)=3 multiplies by 312=4 to give 4(15)−8(6)=12). When the combination isn't obvious (like 41x+15y=1), divide to get the remainders, isolate them in unopened boxes, and back-substitute while grouping matching boxes at every step (1=[4]−1([11]−2[4])=−1[11]+3[4]=…=−4[41]+11[15]).
Generate all integer solutions with zero-sum trades
From one solution (x0,y0), get every integer solution by trading db steps of a against da steps of b:
xy=x0+(db)k,=y0−(da)k(for any integer k)
(For 15x+6y=12 with d=3, all solutions are x=4+2k,y=−8−5k.)
Use gcd(a,b)=1⟺ax+by=1 in proofs
To prove two expressions have GCD 1, combine them so the variable cancels and leaves 1 (like 1(n+1)−1(n)=1); remember not to use this for constants larger than 1, because ax+by=9 only proves gcd(a,b)∣9, not gcd(a,b)=9. When a proof gives you gcd(a,b)=1, write ax+by=1 and multiply by the number you want to isolate (as in Euclid's Lemma: gcd(a,b)=1 and a∣bc⟹acx+bcy=c⟹a∣c).
5
Practice
1
Decide whether each of the equations (a) 18x+12y=20 and (b) 18x+12y=30 has integer solutions. For the one that does, find an integer solution (x,y) by first writing gcd(18,12) as a combination of 18 and 12.
Find gcd(18,12) first. Which of the two right-hand sides is divisible by it?
Since gcd(18,12)=6, an equation 18x+12y=c has integer solutions if and only if 6 divides c.
(a)6 does not divide 20, so 18x+12y=20 has no integer solutions.
(b)6 divides 30, so 18x+12y=30 has integer solutions. One step of 18 minus one step of 12 gives the GCD:
1(18)−1(12)=6
Multiply both step counts by 630=5 (watch out: multiply by 630=5, not by 30, which would give x=30,y=−30 and a total of 180; and keep the minus sign on the second term rather than writing y=5, which would give 150):
5(18)−5(12)=30
An integer solution is x=5,y=−5.
2
Use the Extended Euclidean Algorithm to find integers x and y such that 53x+19y=gcd(53,19).
Watch the negative signs when distributing: in [4]−1([15]−3[4]),−1×(−3[4]) adds +3[4] to give 4[4], whereas subtracting 1−3=−2[4] is a common slip that leads to x=1,y=−4.
Isolate each non-zero remainder in unopened boxes [53],[19],[15],[4],[3], and combine matching boxes after each substitution before plugging in the next line above.
Run the Euclidean Algorithm to find gcd(53,19):
53191543=2(19)+15=1(15)+4=3(4)+3=1(3)+1=3(1)+0
The last non-zero remainder is gcd(53,19)=1. Isolating the remainders in unopened boxes gives:
Back-substitute from the bottom line and group matching boxes at each step (watch the negative signs when distributing: in [4]−1([15]−3[4]),−1×(−3[4]) adds +3[4] to give 4[4], whereas subtracting 1−3=−2[4] is a common slip that leads to x=1,y=−4):
(In the last step, −5×(−2[19])=+10[19] adds to 4[19] to make 14[19]; subtracting 4−10 would give y=−6.) Thus gcd(53,19)=1 with x=−5,y=14.
3
Find all integer solutions to 42x+30y=18, and then find the integer solution in which x is the smallest possible positive integer.
Don't swap the two steps to write x=−6+7k,y=9−5k, which gives x=1,y=4 and 42(1)+30(4)=162=18.
After multiplying your GCD combination to reach 18, divide 30 and 42 by d=gcd(42,30) to find the step counts in each zero-sum trade.
First run the Euclidean Algorithm to find d=gcd(42,30):
423012=1(30)+12=2(12)+6=2(6)+0
So d=6. Substituting [12]=[42]−1[30] into 6=[30]−2[12] gives:
6=[30]−2([42]−1[30])=−2[42]+3[30]
Multiplying both sides by 618=3 gives −6(42)+9(30)=18, so a starting solution is (x0,y0)=(−6,9).
Since db=630=5 and da=642=7, all integer solutions are:
x=−6+5k,y=9−7k(for any integer k)
(Watch out for two slips here: don't forget to divide 30 and 42 by d=6, which would give x=−6+30k and miss five-sixths of the solutions; and don't swap the two steps to write x=−6+7k,y=9−5k, which gives x=1,y=4 and 42(1)+30(4)=162=18.)
For x to be positive, we need −6+5k>0, so 5k>6, which requires k≥2(k=1 gives x=−1, which is still negative). Setting k=2 gives the smallest positive integer x:
x=4,y=−5
4
(a) Prove that for every integer n,gcd(3n+2,2n+1)=1. (b) A student notices that 2(3n+5)−3(2n+2)=4 and concludes that gcd(3n+5,2n+2)=4 for every integer n. State what this equation actually proves about gcd(3n+5,2n+2), and show with n=2 why the student's conclusion is false.
(a) Choose integer multiples of 3n+2 and 2n+1 so the 6n terms cancel out. (b) Any common divisor of a and b divides ax+by, so what does ax+by=4 say about gcd(a,b)?
(a)Multiply 3n+2 by 2 and 2n+1 by −3 so that the n terms cancel:
2(3n+2)−3(2n+1)=(6n+4)−(6n+3)=1
(If you subtract in the reverse order and get 3(2n+1)−2(3n+2)=−1, multiply through by −1 so the right-hand side is +1.) Because 1 is written as an integer combination of 3n+2 and 2n+1 with integers x=2 and y=−3,gcd(3n+2,2n+1) must divide 1, which forces gcd(3n+2,2n+1)=1 for every integer n.
(b)Because the right-hand side is 4 rather than 1, the equation 2(3n+5)−3(2n+2)=4 only proves that gcd(3n+5,2n+2) divides 4 (meaning the GCD can be 1,2, or 4, not necessarily 4). When n=2, the two numbers are 3(2)+5=11 and 2(2)+2=6, and gcd(11,6)=1.
5
Prove that for any integers a,b, and c (with a and b not both zero), if gcd(a,b)=1,a∣c, and b∣c, then ab∣c.
Write ax+by=1 and multiply by c to get acx+bcy=c. Which of c=ak and c=bm should you substitute into each term on the left so that both terms contain ab?
Since gcd(a,b)=1, by Bézout's Identity there exist integers x and y such that
ax+by=1
Multiplying both sides by c gives
acx+bcy=c
Because a∣c and b∣c, there exist integers k and m such that c=ak and c=bm (be sure to use two different letters k and m, since using c=ak and c=bk falsely assumes a=b). Substitute c=bm into the first term (which already has a) and c=ak into the second term (which already has b). Don't plug c=ak into acx and c=bm into bcy, which gives a2kx+b2my=c instead of creating ab:
a(bm)x+b(ak)yab(mx+ky)=c=c
Since mx+ky is an integer, ab∣c. (Alternatively, using Euclid's Lemma: since a∣c, write c=ak; then b∣c becomes b∣ak, and since gcd(a,b)=1, Euclid's Lemma gives b∣k, so k=bm for some integer m and c=abm, meaning ab∣c.)