3.5: The Euclidean Algorithm
( \newcommand{\kernel}{\mathrm{null}\,}\)
Definitions: common divisor
Let a and b be integers, not both 0. A common divisor of a and b is any nonzero integer that divides both a and b. The largest natural number that divides both a and b is called the greatest common divisor of a and b. The greatest common divisor of a and b is denoted by gcd(a, b)
Preview Activity 3.5.1: The GCD and the Division Algorithm
When we speak of the quotient and the remainder when we “divide an integer a by the positive integer b,” we will always mean the quotient q and the remainder r guaranteed by the Quotient Remainder Theorem.
-
Each row in the following table contains values for the integers a and b. In this table, the value of r is the remainder (from the Division Algorithm) when a is divided by b. Complete each row in this table by determining gcd(a, b), r, and gcd(b,r).
a b gcd(a, b) Remainder r gcd(b, r) 44 12 75 21 50 33 -
Formulate a conjecture based on the results of the table in Part (1).
We have already studied a good deal of number theory in this text in our discussion of proof methods. In particular, we have studied even and odd integers, divisibility of integers, and the Quotient-Remainder Theorem.
Before we develop an efficient method for determining the greatest common divisor of two integers, we need to establish some properties of greatest common divisors.
Lemma 3.5.1
Let a,b∈Z with b>0. Then gcd(0, b) = b.
Lemma 3.5.2
Let c and d be integers, not both equal to zero. If q and r are integers such that c=d⋅q+r, then gcd(c, d) = gcd(d, r).
- Proof
-
Let c and d be integers, not both equal to zero. Assume that q and r are integers such that c=d⋅q+r. For ease of notation, we will let
m= gcd(c, d) and n= gcd(d, r).
Now, m divides c and m divides d. Consequently, there exist integers x and y such that c=mx and d=my. Hence,
r=c−d⋅qr=mx−(my)qr=m(x−yq).
But this means that m divides r. Since m divides d and m divides r, m is less than or equal to gcd(d, r). Thus, m≤n.
Using a similar argument, we see that n divides d and n divides r. Since c=d⋅q+r, we can prove that n divides c. Hence, n divides c and n divides d. Thus, n≤ gcd(c, d) or n≤m. We now have m≤n and n≤m. Hence, m=n and gcd(c, d) = gcd(d, r).
Progress Check 3.5.1: Illustrations of Lemma 3.5.2
We completed several examples illustrating Lemma 8.1 in Preview Activity 3.5.1. For another example, let c=56 and d=12. The greatest common divisor of 56 and 12 is 4.
-
According to the Division Algorithm, what is the remainder r when 56 is divided by 12?
-
What is the greatest common divisor of 12 and the remainder r?
The key to finding the greatest common divisor (in more complicated cases) is to use the Division Algorithm again, this time with 12 and r. We now find integers q2 and r2 such that
12=r⋅q2+r2. -
What is the greatest common divisor of r and r2?
- Answer
-
(1) 8
(2) 4; 12 = 8(1) +4
(3) 4
The Euclidean Algorithm
The example in Progress Check 8.2 illustrates the main idea of the Euclidean Algorithm for finding gcd(a, b), which is explained in the proof of the following theorem.
Theorem 3.5.1: Euclidean Algorithm
Let a and b be integers with a>b≥0. Then gcd(a, b) is the only natural number d such that
(a) d divides a and d divides b, and
(b) if k is an integer that divides both a and b, then k divides d.
Note: if b=0 then the gcd(a, b)=a, by Lemma 3.5.1.
- Proof
-
Let a and b be integers with a>b≥0, and let d= gcd(a, b). By the Quotient Remainder Theorem, there exist integers q1 and r1 such that
a=b⋅q1+r1, and 0≤r1<b.
If r1=0, then equation (8.1.3) implies that b divides a. Hence, b=d= gcd(a, b) and this number satisfies Conditions (a) and (b).
If r1>0, then by Lemma 8.1, gcd(a, b) = gcd(b, r1). We use the Division Algorithm again to obtain integers q2 and r2 such that
b=r1⋅q2+r2, and 0≤r2<r1.
If r2=0, then equation (8.1.4) implies that r1 divides b. This means that r1= gcd(b, r1). But we have already seen that gcd(a, b) = gcd(b, r1). Hence, r1= gcd(a, b). In addition, if k is an integer that divides both a and b, then, using equation (8.1.3), we see that r1=a−b⋅q1 and, hence k divides r1. This shows that r1= gcd(a, b) satisfies Conditions (a) and (b).
If r2>0, then by Lemma 8.1, gcd(b, r1) = gcd(r1, r2). But we have already seen that gcd(a, b) = gcd(b, r1). Hence, gcd(a, b) = gcd(r1, r2). We now continue to apply the Division Algorithm to produce a sequence of pairs of integers (all of which have the same greatest common divisor). This is summarized in the following table:
Original Pair Equation from Division Inequality from Division Algorithm New Pair (a,b) a=b⋅q1+r1 0≤r1<b (b,r1) (b,r1) b=r1⋅q2+r2 0≤r2<r1 (r1,r2) (r1,r2) r1=r2⋅q1+r3 0≤r3<r2 (r2,r3) (r2,r3) r2=r3⋅q1+r4 0≤r4<r3 (r3,r4) (r3,r4) r3=r4⋅q1+r5 0≤r5<r4 (r4,r5) ... ... ... ... From the inequalities in the third column of this table, we have a strictly decreasing sequence of nonnegative integers (b>r1>r2>r3>r4⋅⋅⋅). Consequently, a term in this sequence must eventually be equal to zero. Let p be the smallest natural number such that rp+1=0. This means that the last two rows in the preceding table will be
Original Pair Equation from Division Algorithm Inequality from Division Algorithm New Pair (rp−2,rp−1) rp−2=rp−1⋅qp+rp 0≤rp<rp−1 (rp−1,rp) (rp−1,rp) rp−1=rp⋅qp+1+0 Remember that this table was constructed by repeated use of Lemma 8.1 and that the greatest common divisor of each pair of integers produced equals gcd(a, b). Also, the last row in the table indicates that rp divides rp−1. This means that gcd(rp−1,rp) =rp and hence rp= gcd(a, b).
This proves that rp= gcd(a, b) satisfies Condition (a) of this theorem. Now assume that k is an integer such that k divides a and k divides b. We proceed through the table row by row. First, since r1=a−b⋅q, we see that
k must divide r1.
The second row tells us that r2=b−r1⋅q2. Since k divides b and k divides r1, we conclude that
k divides r2.
Continuing with each row, we see that k divides each of the remainders r1,r2,r3,...,rp. This means that rp= gcd(a, b) satisfies Condition (b) of the theorem.
Example 3.5.1: (Using the Euclidean Algorithm)
Let a=234 and b=−42. We will use the Euclidean Algorithm to determine gcd(234, 42).
Step | Original Pair | Equation from Division Algorithm | New Pair |
1 | (234, 42) | 234=42⋅5+24 | (42, 24) |
2 | (42, 24) | 42=24⋅1+18 | (24, 18) |
3 | (24, 18) | 24=18⋅1+6 | (18, 6) |
4 | (18, 6) | 18=6⋅3 |
So gcd(234, 42) = 6 and hence gcd(234, -42) = 6.
Exercises
Exercise 3.5.1:
1. Find each of the following greatest common divisors by using the Euclidean Algorithm.
(a) gcd(21, 2511) (b) gcd(110, 2511) (c) gcd(509,1177)
2. Find each of the following greatest common divisors by using the Euclidean Algorithm.
(a) gcd(10933, 832) (b) gcd(1265,18400)
3. Let a,b∈Z+ find
(a) gcd(a,1) (b) gcd(a,a) (c) gcd(a,0) if a>0 (d) gcd(a,35) if a=35b+14
- Answer:
-
(a) 1 (b) a (c) a (d) 7
4. Disprove mod is distributive over multiplication for the set Z+, i.e. using a,b,c∈Z+.