Chapter 1 A Survey of Divisibility 14 SECTION C Euclidean Algorithm By the end of this section you will be able to use properties of the greatest common divisor (gcd) obtain the gcd using the Euclidean algorithm solve linear equations C1 Properties of the Greatest Common Divisor In this section we investigate some of the properties of the gcd and we introduce the Euclidean Algorithm, which provides a way to find the gcd of two integers. We begin by looking at solution at equations of the form: ax by gcd( a,), b where a, b, x and y are integers. Example 14 In Example 8 from Section A we found and y: Solution 36x 60y 12 gcd 36, 60 12, let us solve for integers x We have a linear equation with two unknowns. How can we solve this equation? First divide through by 12 as it is a common factor, this reduces it to: Now rearrange to make y the subject:, 3x 5y 1. 1 3 x y. 5 Remember that x and y are integers (they could be negative). This means that we can choose any integer x as long as and the resulting value for y is also an integer. For example, letting x 2 then 1 3 2 y 1. 5 There are going to be many other pairs of x and y which work. We can also solve the equation using graphs because 36x 60y 12 is equivalent to 1 3x y (see Example 14), which is a straight line as shown in 3: 5
Chapter 1 A Survey of Divisibility 15 Figure 3 The graph shows two integer solutions to 36x 60y 12 As you can observe from the graph there are two integer points (pairs) which are on the line 36x 60y 12. For instance the point 2, 1 that we found in Example 14, but we could also have found the solution x 3, y 2 which is the point 3, 2. Indeed there are an infinite number of integer points on the line 36x 60y 12. This leads us to ask, can we always find integers x and y such that ax by g where g gcd a, b It turns out that indeed we can, as we now prove.? Proposition (1.9). There are integers x and y such that How do we prove this result? ax by gcd a, b g First we show ax by is a common divisor of a and b and then we prove ax by is the largest of these common divisors. Proof. Common Divisor Consider the set S given by where both integers a and b are not zero. The set S is non-empty. Why? Let the integers x S ax by : ax by 0 a and y b (we select these integers so that ax by 0 ) then ax by a b 2 2 Therefore S is non-empty so by Well Ordering Principle (WOP): 0
Chapter 1 A Survey of Divisibility 16 Let S be a non-empty set of positive integers and zero. Then the set S has a least element. Let d be the least element of the above set S. This means there are integers x and y such that ax by d. (*) To show that d is a common divisor of a and b we make use of the Division Algorithm (1.7) of the last section: Given any integers m and n with n 1 m qn r 0 r n there exist unique integers q and r such that We start by showing that d is a divisor of a by applying the Division Algorithm (1.7): a qd r 0 r d ( ) Suppose r 0, then transposing a qd r to make r the subject yields r a qd Substituting ax by d from (*) into this gives 1 r a q ax by qx a qyb a 1 qx b qy 0 Because r 0 integer integer This implies that r is in the set S because S is defined as S ax by : ax by 0 But if r is in the set then since r<d we would have a contradiction as d is the least element. Therefore, our supposition r 0 is wrong, meaning r 0, and so a qd, which implies d a. Similarly by applying the Division Algorithm to integers b and d we can show that d b. Hence d is a common divisor of a and b. Since d a and d b it follows from Proposition (1.3): d a d b then d ax by If and that d () ax by. Largest Common Divisor for any integers x and y. Next we show d to be the greatest common divisor, gcd, of a and b. Let c be another divisor of ax by d then by (1.2) part (e) (e) If a b and b 0 then a b.
Chapter 1 A Survey of Divisibility 17 It follows that as c d where d and c are both positive c d which means d must be the greatest common divisor, gcd, of integers a and b. That is, d=g. By the above proof we also have the following two propositions: Proposition (1.10). Let gcd a, b g then (i) If d a and d b then d g. (ii) The gcd a, b g is the least positive integer value of ma nb range over all the integers. where m and n Proof. See proof of the above Proposition (1.9). Proposition (1.11). Let gcd a, b g. For any positive integer m gcd, Proof. ma mb mg By applying the above Proposition (1.10) part (ii) we have ma mb least positive value of max mby gcd, m (least positive value of ax by ) mg C2 Relatively Prime We encountered the idea of two numbers being relatively prime back in Section A. The two integers 10 and 21 are relatively prime as they have no factor in common apart from 1. The formal definition is: Definition (1.12). Integers a and b not both zero are relatively prime if gcd a, b 1 Another example of relatively prime numbers is: gcd 5, 13 1 therefore 5 and 13 are relatively prime In the next example we use the fact that 5 and 13 are relatively prime.
Chapter 1 A Survey of Divisibility 18 An important result concerning relatively prime numbers is Euclid s Lemma. It is worth learning this result as it is used throughout number theory. (Usually lemma means an intermediate result or a result used to deduce an important theorem or proposition but in this case Euclid s Lemma is a critical result in its own right.) Euclid s Lemma (1.13). If a b c gcd a, b 1 then a c. with Before we prove this let us see it in action. Example 15 Given 13 5117 show that 13 117. Solution gcd 13, 5 1 and so by Euclid s Lemma (1.13) we have 13 117. Let us now prove the Lemma. Proof. By Proposition (1.5) of the last section: Proposition (1.5). If gcd a, b g There are integers m and n such that then there are integers m and n such that ma nb g ma nb 1. [Because we are given gcd a, b g 1 ] Multiplying both sides by an integer c gives cma cnb m ac n bc c. (*) Now, we are given that a b c therefore there is an integer k such that Substituting this into (*) gives The result a mc nk c This completes our proof. ak bc. () m ac n bc m ac n ak a mc nk c means that a integer Factorizing By (*) c so we have a c
Chapter 1 A Survey of Divisibility 19 Figure 4 Euclid is famously known for his work The Elements which is also called Euclid s Elements. This work has been used in mathematics teaching for over two thousand years and was first published as a book in 1482. Only the bible has been printed more times than Euclid s Elements. Up until the 1970 s school mathematics in Britain consisted of learning various parts of Euclid s Elements. The concept of mathematical proof and logical reasoning is what made this work survive for so long. C3 Euclidean Algorithm The Euclidean algorithm is used to find the gcd of any two positive integers. Say we are asked to determine the gcd5291, 3108. How are we going to find the greatest common divisor of these numbers? Listing the divisors of each and looking for divisors which are common to both numbers will take considerable time. We need a simpler approach the Euclidean algorithm. The Euclidean algorithm is the most efficient way of finding the gcd of any two integers as it removes the need to find all the factors of the two given integers. This is quicker and less tedious than finding all the factors, especially if the integers are large. Next we describe the Euclidean algorithm which is based on the repeated application of the Division Algorithm (1.7) of the last section: Division Algorithm (1.7) Given any integers a and b with b 1 integers q and r such that a bq r 0 r b there exist unique We repeated apply the Division Algorithm to the two given integers a and b, the gcd of these given integers a and b turns out to be the last non-zero remainder as the next example demonstrates: Example 16 Determine gcd666, 31. Solution We underline the remainder at each step for clarity. Applying the division algorithm to 666 and 31 gives 666 21 31 15
Chapter 1 A Survey of Divisibility 20 The remainder is 15 which is non-zero so we apply the division algorithm to 31 and 15: 31 2 15 1 Again the remainder 1 is non-zero so we continue to apply the division algorithm to 15 and 1: 15 15 1 0 Now we have a remainder of zero which means we stop the process. What is gcd 666, 31 equal to? It is the last non-zero remainder which is 1. Hence gcd666, 31 1 relatively prime. that is they are The general Euclidean algorithm procedure for a b 1 is given by: 1. Dividing a and b and applying the division algorithm gives 2. If the remainder r 1 0 then a bq1 a bq r 0 r b 1 1 1 and gcd, gcd, means we are done because we have found gcd a, b b. a b bq b b. This 3. If r1 0 then a bq1 r1 and we divide b by r 1. Writing this in terms of quotient q2 and remainder r 2 gives 4. If the remainder r2 0 b r q r 0 r r 1 2 2 2 1 then we are done. Otherwise we repeat the above process of applying the division algorithm to r 1 and r 2. We continue in this manner until we get a remainder of zero. 5. The last non-zero remainder is the gcd of the given integers a and b. We will prove step 2 below. However prior to the proof of this we will demonstrate the Euclidean algorithm with an example. Example 17 By applying the Euclidean algorithm find gcd 5291, 3108 and simplify 5291 3108. Solution Dividing 5291 by 3108 gives 5291 1 3108 2183 Since we do not have a zero remainder we continue to apply the division algorithm until we get a zero remainder: 1
Chapter 1 A Survey of Divisibility 21 The last non-zero remainder is 37 so 5291 1 3108 2183 3108 1 2183 925 2183 2 925 333 925 2 333 259 333 1 259 74 259 3 74 37 74 2 37 0 gcd 5291, 3108 37 How can we simplify the given fraction 5291 3108? By Proposition (1.5) of Section A: Last non-zero remainder. If gcd a, b g a b then gcd, 1. g g This means that dividing the numerator 5291 and denominator 3108 by 37 which is the gcd gives no factors in common after division. Therefore 5291 14337 143 3108 8437 84 Cancelling 37's This 143/84 is the simplest fraction of 5291/3108 because by (1.5) we have gcd 143, 84 1 So these numbers (143 and 84) are relatively prime. We need to prove that the gcd of given integers a and b is equal to the gcd of b and r where r is the remainder when we divide a and b. [This was step 2 of the Euclidean algorithm.] Proposition (1.14). If a bq r 0 r b Then g gcd a, b gcd b, r Proof... Required to prove that g g. 1 2 Let g gcd a, b 1 and g gcd 2 b, r From g gcd 1 a, b we have g, g 1 1 a b and we are given a bq r so g 1 r. Since g b and g 1 1 r so g 1 is a common divisor of b and r so by the definition (1.4): (ii) if for any c we have c x and c y then c g where g gcd x, y.
Chapter 1 A Survey of Divisibility 22 We have g g because g 1 2 2 gcd b, r Similarly by considering g2 gcd b, r Hence g g. 1 2. we can deduce that g g. 2 1 C4 Solving Linear Equations We can use the Euclidean algorithm in reverse order to solve linear Diophantine equations like 666 x 31 y gcd 666, 31 In Example 16 we found gcd 666, 31 1. Thus this linear equation is 666x 31y 1 It is going to have an infinite number of solutions. Why? Drawing the graph of this straight line 666x 31y 1 : Figure 5 Showing an integer solution of the line 666x 31y 1. Any point on this straight line is a solution to 666x 31y 1. However we are only interested in integer solutions to this equation. How can we find integer solutions? We can use Example 16 because we had: From (**) we have 666 21 31 15(*) 31 2 15 1 ** 1 31 2 15 31 2 666 21 31 By (*) 31 2 666 42 31 Expanding the brackets 43 31 2 666 Collecting like terms
Chapter 1 A Survey of Divisibility 23 We have 3143 666 2 1 of x and y?. We wanted to solve 666x 31y 1. What are the values Clearly x 2 and y 43. This is the point shown on the above graph in Fig. 5. Example 18 Solve 5291x 3108y gcd 5291, 3108 Solution for integer solutions. What are we trying to find? The integer values of x and y which satisfy the given equation. We have already found the gcd of 5291 and 3108 in Example 17. We had the following (step numbers have been added): 5291 13108 2183 1 3108 12183 925 2 2183 2925 333 3 925 2333 259 4 333 1259 74 5 259 374 37 6 37 was the last non-zero remainder so gcd 5291, 3108 37 reverse order to obtain integer values of x and y such that From step (6) we can write 37 as 5291x 3108y 37 37 259 374 259 3333 259 Using step (5) 4259 3333 Collecting like terms 4925 2333 3333 Using step (4) 4925 11333 Collecting like terms 4925 112183 2925 Using step (3) 26925 112183 Collecting like terms 263108 2183 112183 Using step (2) 263108 372183 Collecting like terms 263108 375291 3108 Using step (1) 633108 375291 Collecting like terms We have 633108 375291 =37. What are the values of x and y in Re-writing this 633108 375291 =37 5291x 3108y 37? as. We use these 6 steps in
Chapter 1 A Survey of Divisibility 24 310863 529137 =37 yields x 37 and y 63 The value 37 is the smallest positive integer of 5291x 3108y. How do we know this? Because of Proposition (1.10) part (ii): (ii) The gcd a, b g is the least positive integer value of ma nb range over all the integers. What can you say about the linear equation 5291x 3108y 36? It has no integer solutions because the least value of this linear combination 5291x 3108y is 37. where m and n Note that by applying the Euclidean algorithm we can find the gcd of any two positive integers a and b plus solve the linear equation for integer solutions. SUMMARY ax by gcd a, b We use the Euclidean algorithm to find the gcd of two numbers a and b. By reversing the steps of the Euclidean algorithm we can solve the linear equation ax by gcd a, b