Bezout's Lemma and the Fundemental Theorem of Arithmetic

Unlimited Power ⛈️

Now that we have the machinery1 of the gcd and general divisibility, we can touch on a theorem that will unlock us the ability to prove a ton of problems that otherwise would have been super freaking annoying to solve without it. Note that much of the information on this page was referenced from brilliant.org which is a great resource for such information.

Bezout’s Lemma: For all values of a,b,kZ, the equation ax+by=k where x,y are integer variables has a solution iff gcd(a,b)|k

This solution is actually quite insane, as we can see whether or not there will be solutions to equations by observing the Euclidean Algorithm.

5x+3y=1, gcd(5,3)=1|1 so we know a solution exists. 2x+4y=15 gcd(2,4)=215 which means no solution exists. This will have many applications, but let us first provide the proof.

First, the forward direction that solution exists implies gcd(a,b)|k is quite easy by contrapositive, as if gcd(a,b)k then if you divided both sides by the gcd then kgcd(a,b) would not be an integer and the equation would not be solvable with integers. Now for the more challenging direction

In order to prove that gcd(a,b)|k implies solution exists we will actually provide an algorithm to find the solution. This algorithm is called the Extended Euclidean Algorithm and actually is just the Euclidean Algorithm, but holding onto some extra variables.

The idea of the algorithm is that we are going to find values (x0,y0),(x1,y1), such that at every step we get rj=axj+bxj where each rj is a remainder in the Euclidean Algorithm. If we can eventually get to the final step, we will be able to solve the equation for the gcd(a,b). We start with x0=1,y0=0,r0=ax1=0,y1=1,r1=b. This should make sense as then ax0+by0=a and ax1+by1=b which is correct. From here we proceed with the Euclidean algorithm as well as two additional steps. Let a=qb+r2r2=aq1b and in general we would have rn+1=rn1qnrn with qn=rn1rn. Taking this value of qn we will say that xn+1=xn1qnxnyn+1=yn1qnyn.

We can show that this algorithm will always produce valid steps as axn+1+byn+1=a(xn1qnxn)+b(yn1qnyn)=(axn1+byn1)qn(axn+byn)=rn1qnrn=rn+1. Therefore, as long as we eventually reach the gcd(a,b) we will find a value of x,y that solves the equation; since the Euclidean algorithm guarantees the gcd, this is done.

If k=gcd(a,b) then we are done, however if k=cgcd(a,b), then find the final solutions of x,y that solve for the gcd, and then multiply both sides of the equation by c. This proves our claim

QED.

Holy shit that was a lot. When I taught this for the first time to my students, literally 0 people understood what was going on, so it might be worthwhile to go through an example. Notice that this algorithm is also O(logn) as its just the Euclidean algorithm but with some additional steps each iteration.


Walking through the Extended Euclidean Algorithm

Example: Find values x,y that satisfy 134x120y=12

We will, by hand, compute the extended Euclidean Algorithm to solve this problem. We start with r0=134,x0=1,y0=0134(1)120(0)=134r1=120,x1=0,y1=1134(0)120(1)=120 We now proceed with the next step. 134=(120)(1)+14 which means that q1=1 and r2=14. Also x2=x0q1x1=(1)(1)(0)=1y2=y0q1y1=(0)(1)(1)=1 which gives us that 134(1)120(1)=14 which is correct. We now go to the next step to see 120=14(8)8 so q2=(8) and r3=8. x3=x1q2x2=(0)(8)(1)=8y3=y1q2y2=(1)(8)(1)=9 and again we get 134(8)120(9)=8 which is true. We still have not hit a remainder of 0 yet so we continue. 14=(8)(1)+6 meaning q3=1 and r4=6. x4=x2q3x3=(1)(1)(8)=9y4=y2q3y3=(1)(1)(9)=10 and to confirm we find that 134(9)120(10)=6. Continuing we get that 8=(6)(1)2 with q4=1 and r5=2. x5=x3q4x4=(8)(1)(9)=17y5=y3q4y4=(9)(1)(10)=19 shockingly we find that 134(17)120(19)=2. When we do 6=(2)(3) we find a remainder of 0 which means our algorithm is done. While we could leave it like this, we generally want to present our gcd positive, so we would multiply both sides by 1 to get (1)(134(17)120(19))=(1)(2)134(17)120(19)=2 Now since we want to solve for when the equation equals 12, we can multiply both sides by 12gcd(134,120)=6 to get that (6)(134(17)120(19))=(6)(2)134(102)120(114)=12, which plugging into a calculator we find is correct! So a valid solution is x=102 and y=114. If we wanted smaller positive numbers, we could add 120 and 134 to our solutions which would cancel out but make things easier, so 134(102+120)120(114+134)=134(102)120(114)+134120134120=12 so we get 102+120=18 and 114+134=20 134(18)120(20)=12

so x=18 and y=20 is another valid solution.


Silly Results with Bezout’s Lemma

The solving of integer equations opens us up to some funny results as we can create word problems for them. One that I used personally was

Example: One trip on the PATH train with a metrocard costs 2.75$.SupposeourcardcurrentlyhasMonit.Everytimewedonothaveenoughmoneyonthecardforatrip,werefilitwith20. For what values of x will the card eventually reach $$0$ with no leftover money?

Solution First, represent all values in terms of cents, so we don't need to worry about decimals. So M is in cents, it costs 275 per trip, and we refill with 2000. If we refill x times, and take y trips, we want to find values x,y such that M+2000x275y=02000x275y=M. By Bezout's Lemma we know that a solution exists if and only if gcd(275,2000)|M and since the gcd is 25, the value on the card will reach 0 if M contains any dollar amount with 0,25,50,75 cents.
Q.E.D.

Fun little side thing is that if the gcd of the amount you refill and 275 is 1, then any value of M will eventually reach 0! In order to do this just be unhinged as fuck and refill with 6.79 every time since 275=5211.


The Fundemental Theorem of Arithmetic

Now that we have access to Bezout’s Lemma, we now have the tools that we need to easily prove the Fundemental Theorem of Arithmetic, which forms the basis of number theory and why we really care so much about prime numbers.

But first before we actually explain what that is, we need to prove something called Euclid’s Lemma first. Funny enough this little Lemma is why we need Bezout’s Lemma, if we just took it by assumption then we could have skipped all this effort LOL. Crazier, Euclid proved this shit using fucking Geometry what a psychopath 🔪🩸

Euclid’s Lemma: Let p be a prime number. If p|ab then p|a or p|b.

Proof In order to prove this, we will show that if pa then its required that p|b which is sufficient to prove, as if p|a then we're done. We know that p|ab which means thatab=kp. Since p|a and p is prime, then gcd(a,p)=1 since the only factor of p is p and 1. As such by Bezout's Lemma we know that px+ay=1 has a solution. Multiply both sides by b to get that pbx+aby=b. Notice before that we said ab=kp so we can substitute to get that pbx+kpy=bp(bx+ky)=b which means that p|b as we know a solution exists and otherwise bp would not be an integer. This proves our claim.
Q.E.D.

With this result we are now ready to tackle the Fundemental Theorem.

Fundemental Theorem of Arithmetic: For every integer n>1, either n is prime, or there exists a unique product of primes n=p1k1p2k2pmkm. In other words, every number has a prime factorization.

This is how we know that every number can be broken up into prime factors! Now like many theorems, this one has two pieces. The first is showing that a factorization always exists, and the second is showing that every number has only one factorization2. We will do these two proofs seperately; existence is easy, uniqueness is hard (kinda).

The existence proof comes from the way that we often ourselves do factoring. Suppose I wanted to factor 244, well I could see that 2|244, so dividing I’d find that 244=2122 and now our problem is reduced to finding the factors of 122! This is effectively strong induction which is why we will use strong induction to prove.

Existence Proof Our base case is n=2 which is prime. We will now perform the induction step. Consider some value of n>2 and assume that all integers less than n satisfy our hypothesis. If n is prime then we are done. If n is not prime, then there is some number 1<k<n such that k|n which means n=kx for some value of x. Since both k,x<n by our strong induction hypothesis we know that they both have prime factorizations. As such we can multiply these prime factorizations to get a prime factorization for n.
Q.E.D.

Now to prove uniqueness we will do exactly the same thing we do for all uniqueness proofs; assume there are two different versions and then prove that they must be the same.

Uniqueness Proof Suppose that for some value of n we have two distinct prime products n=p1k1p2k2pmkm, and n=q1j1q2j2qrjr, Where values of p,q are prime. Let us begin by first observing that p1|n by definition, so p1|q1j1q2j2qrjr and since p1 is prime, by Euclid's Lemma we know that p1 must divide some qiji. For the sake of convenience say that p1|q1j1 since q1 is also prime, we can see that p1|q1 which means that p1=q1. We can continually apply this process to see that in fact every prime pi=qi and m=r which makes the two factorizations the same, proving our claim.
Q.E.D.

This result actually is quite massive, as it shows us that we can always factorize any integer3. Perhaps this result is boring to the people who were already aware that you could factorize integers and didn’t really care why it was why it was. In the future I will put a section here on algorithms for prime factorizing


Practice Problems

Example: Find a value x,y such that 76x+12y=16

Theorem: Let gcd(n,a)=1 and n|ab. Then n|b

Theorem: Let p be prime and p|an. Then p|a


  1. Term mathematicians use to describe the idea that we have clean ways of doing and describing things ↩︎

  2. Shuffling the terms is considered the same product ↩︎

  3. For negative numbers you just include 1 as a factor, which is why I’ve seen 1 referenced as “the prime at infinity” even though that doesn’t entirely make sense but whatevs 🤷 ↩︎

Previous
Next