Let a and b be naturals that are not both zero. The greatest common divisor of a and b, denoted gcd(a,b) is the largest integer that divides both a and b. Similarly, the least common multiple, denoted lcm(a,b) is the smallest integer that is divided by every element both. Both of these concepts are generalized to more than two elements, although we will rarely use them.
Two integers a and b are called coprime or relatively prime if gcd(a,b)=1. I denote this phenomenon by a⊥b.
Reflect.
What does the word largest in the definition above mean precisely? Am I referring to the usual order of integers ≤, or the divisibility order ∣ instead? What is the relationship between these two anyway?
Exercises.
If a prime p does not divide a, then p⊥a.
Prove that consecutive integers are coprime.
If p is prime and gcd(p,n)>1, then p∣n. If, moreover n is also prime, then necessarily p=n.
Different primes are always coprime. Show with an example that the converse does not hold. That is, show that coprime numbers need not be prime.
Exercise.
Let p,q be integers and d their GCD. Then, p/d and q/d are relative primes.
The Euclidean algorithm
I now introduce one of many examples in mathematics where the statement of the theorem is not that important, but the proof is crucial to understand the material.
Theorem (Euclidean algorithm).
Assume that, for naturals a and d≥1, the Q-R formula gives a=dq+r. Then,
gcd(a,d)=gcd(d,r).
Reflect.
Again, spend some time thinking why is this called an algorithm; there aren’t any steps!
Exercise.
Use the theorem to implement this as an actual computer program that computes the gcd.
Solution.
Recursion is elegant. (But can be wildly inefficient too.)
def gcd(a, b): if b==0: return abs(a) # absolute value return gcd(b, a%b)
I will answer the important question of how to use this in the following subsection. More importantly, I will skip the proof for now, since understanding a particular case should make the proof idea apparent.
The extended Euclidean algorithm
Note:
These sort of examples with many moving steps are best understood during a live lecture, not reading them on a static site.
Let me do an example where I compute gcd(56,15) using the Euclidean algorithm.
First I divide and find the remainder: 56=15⋅3+11. Thus, gcd(56,15)=gcd(15,11).
Now I repeat these steps until I reach something trivial. Note: if you do not know why this must happen eventually, you have not understood the theorem and should go back to the previous section.
15=11⋅1+4dividing 15 by 1111=4⋅2+3dividing 11 by 44=3⋅1+1dividing 4 by 33=1⋅3+0
The last remainder before reaching zero is always the gcd; in this case gcd(56,15)=1.
Reflect.
What would happen if I wanted to compute gcd(15,56) instead? Obviously it should give me the same answer, but the algorithm does something different, since it always divides the left by the right. How does this work?
Notice that I can do the steps in reverse and obtain the remainder as a linear combination of the two previous rows. Repeatedly doing this backwards, I can write the final remainder in terms of the first two terms, 56 and 15. The math paragraph below should be read from bottom to top, so it aligns with the math paragraph above.
1=(−4)56+(3)15in terms of 56 and 151=(3)15+(−4)11in terms of 15 and 111=(−1)11+(3)4in terms of 11 and 41=4+(−1)3in terms of 4 and 3
Therefore, gcd(56,15)=1=(−4)56+(3)15. The fact that the gcd is a linear combination of the numbers can be proved more directly too. This is the purpose of the next section.
Bézout’s identity
Here is an important result that can be proved using Induction.
Theorem (Bézout's identity)
The least linear combination of two integers, not both zero, a and b is precisely gcd(a,b).
In particular, a and b are coprime if and only if there exist integers x,y such that ax+by=1.
Exercise.
Prove that the product of two relative primes that divide n, divides n.
The following consequences follow rather easily, but are non trivial if proved from just the definitions.
Exercise (Euclid's lemma 1).
If p is prime and p∣ab, then either p∣a or p∣b.
The same idea can be used to prove the slightly more general result:
(Euclid's lemma 2)
Suppose that a⊥b and a∣bc, then a∣c.
Exercise.
Prove that for every integer at least 5 of the form n=6k±1, n2−1 is divisible by 24.
Hard exercise.
Prove this generalization of Bézout’s identity. Let n be a positive natural and take a set of integers {a1,…,an}={0}. Then,