Greatest Common Divisors Reading The reading is contained in section 4.3. Specifically, you should read starting from the section on “Greatest Common Divisors and Least Common Multiples” up until the end of the section, but you can ignore everything about prime numbers and prime factorizations and so forth. Summary The greatest common divisor of two integers a and b, not both zero, is the largest positive integer which divides both a and b. It is denoted gcd(a, b). We define gcd(0, 0) = 0 by convention. The integers a and b are relatively prime, or coprime, if gcd(a, b) = 1. Example 1. An important basic example to keep in mind is that, for any integer a, we have gcd(a, 0) = |a|. You should convince yourself of why this is true. Theorem 2. Let a and b be integers, not both of which are zero. (a) There exist integers s and t such that gcd(a, b) = as + bt. (b) Every integer that can be written in the form ax + by for some x, y ∈ Z is a multiple of gcd(a, b). (c) Every common divisor of a and b divides gcd(a, b). Proof. The reason for lumping four statements into one theorem is that we’re going to prove all of them together! Consider the set D = {ax + by : x, y ∈ Z} ∩ (N \ {0}). It is clearly nonempty. For example, taking x = a and y = b shows us that a2 + b2 ∈ D (it is clearly positive, and it is nonzero because we assumed that not both a and b are zero). By the well-ordering principle, there is a least element d ∈ D. We’re going to end up showing that d = gcd(a, b), but we don’t know that yet. In the process of showing this, we’ll actually end up showing all of the statements in the theorem. First, note that since d ∈ D, there exist s, t ∈ Z such that d = as + bt. Let us prove that every element that can be written in the form ax + by for some x, y ∈ Z is divisible by d. Let r be the remainder upon dividing ax + by by d. Then r = (ax + by) − dq = (ax + by) − (as + bt)q = a(x − sq) + b(y − tq) where q is the quotient. We know that 0 ≤ r < d, so either r = 0, or else r ∈ D. But if r ∈ D we have a contradiction, since d was the smallest element of D. Thus we must have r = 0, so d | (ax + by) for all x, y ∈ Z. In particular, taking x = 1 and y = 0 shows that d | a, and taking x = 0 and y = 1 shows that d | b. In other words, d is a common divisor of a and b. Now if c is another common divisor of a and b, then c also divides as + bt = d. This means that c ≤ d, so d is the largest of the common divisors of a and b. In other words, d = gcd(a, b). At this point, we’ve showed everything we said we were going to prove. You should go through this proof and check that we’ve actually done this. Proposition 3. Let a and b be integers with b > 0. Let r be the remainder of dividing a by b. Then gcd(a, b) = gcd(b, r). Proof. Let q be the quotient of dividing a by b, so that a = bq + r. Then r = a − bq, so if d = gcd(a, b), then d | r using part (d) of the theorem. So d divides both b and r. If c is a common divisor of b and r, then clearly c also must divide bq + r = a, so c is also a common divisor of b and a, so c | d. Thus d is a common divisor of b and r, and every common divisor of b and r also divides d, so d = gcd(b, r). 1 Example 4. Proposition 3 actually gives us a very efficient algorithm for computing greatest common divisors called the euclidean algorithm. I think it’s more confusing to describe in the abstract, and the mathematical essense of the algorithm is just proposition 3, so I won’t bother. Instead, let’s work through it in an example. Let a = 96 and b = 9. Dividing, we get 96 = 9 · 10 + 6. The proposition tells us that gcd(96, 9) = gcd(9, 6). Probably at this point you can compute gcd(9, 6) in your head, but say you couldn’t. Well, you can just repeat this division process! We can write 9 = 6 · 1 + 3, so gcd(9, 6) = gcd(6, 3). Now we can write 6 = 3 · 2 + 0, so gcd(6, 3) = gcd(3, 0) and we know from example 1 that this is equal to 3. Thus, gcd(96, 9) = 3. You should be able to adapt this example to other situations, to write down an abstract description of the algorithm described here, and if you like programming, to be able to turn this into a computer program. There is one point that isn’t clear from examples and needs to be proved in the abstract, which is that no matter what a and b > 0 you start with, at some point you’ll end up with computing the gcd of something and 0. You should try to prove this yourself. Hint: notice that the “b” in each iteration of the euclidean algorithm keeps getting smaller! Example 5. By being more careful with the euclidean algorithm, we can actually figure out integers s and t such that gcd(a, b) = as + bt. Again, let’s do this in an example. This is not the most efficient process: you can be more clever and more efficient by using the “extended euclidean algorithm,” but the mathematical essence of that algorithm is the same as what’s described here. Again, let’s do this with the example we had before, where a = 96 and b = 9. In the end, we saw that the gcd was equal to gcd(3, 0) = 3. Notice that at this final step, it’s really easy to express 3 as a linear combination of 3 and 0: specifically, we can take 3 = 3 · 1 + 0 · 0. Now remember that we got to 3 because it was the remainder upon dividing 9 by 6. We had 9 = 6 · 1 + 3, which means that 3 = 9 − 6 · 1. So let’s substitute this in instead of 3, and we get 3 = (9 − 6 · 1) · 1 + 0 · 0 = 9 − 6 · 1. Now remember that we got to 6 because it was the remainder of dividing 96 by 9. In other words, we have 6 = 96 − 9 · 10, so again substituting, we get gcd(96, 9) = 3 = 9 − (96 − 9 · 10) = 9 · 11 − 96. So we can take s = −1 and t = 11. Proposition 6. If a | (bc) for some integers a, b and c, then a | gcd(a, b) · c. Proof. There exist s, t such that gcd(a, b) = as + bt. Then gcd(a, b) · c = asc + btc. Clearly a | (asc). We assumed that a | (bc), so a | (btc). Thus a divides both sides of the right hand side, so a | gcd(a, b) · c. Corollary 7. If a and b are relatively prime integers and a | (bc) for some integer c, then a | c. The least common multiple of two nonzero integers a and b is the smallest of the positive common multipes of a and b. It is denoted lcm(a, b). It is closely related to the gcd by the following result. Proposition 8. Let a and b be positive integers. Then ab = gcd(a, b) · lcm(a, b). Proof. This is exercise 31 in Rosen, 4.3. You can prove this using prime factorizations, but you don’t need to use them. It might be good practice to try to prove it without using prime factorizations. 2 Comments (1) A lot of facts about greatest common divisors can be proved using prime factorizations. We’ll see a formula for gcd(a, b) in terms of prime factorizations of a and b next lecture, but there are two reasons it’s good to be able to prove things without using prime factorizations. Firstly, if you’re interested in applications, computing prime factorizations is very difficult. For example, it is much quicker to compute greatest common divisors using the euclidean algorithm. In general, if you find yourself needing to do anything with greatest common divisors when writing a computer program, you’ll likely end up using one of their properties listed in theorem 2. Secondly, if you’re interested in theory, the notion of greatest common divisors generalizes, vaguely speaking, to the notion of “ideals” in ring theory. Some rings don’t have prime factorizations, but you can still deal with their ideals like you would deal with greatest common divisors of integers. (2) Theorem 2 has, as a consequence, that given three integers a, b and d ≥ 0, the following three conditions are equivalent. (a) d = gcd(a, b). (b) d is a common divisor of a and b, and every common divisor of a and b is also a divisor of d. (c) d = as + bt for some integers s and t, and every integer of the form ax + by for some integers x and y is a multiple of d. Often, you prove that some integer is the greatest common divisor of some pair by using one of these two conditions. Examples Here is a list of facts that you should be able to prove. (a) If a and b are relatively prime integers and a | c and b | c for some integer c, then (ab) | c. (b) If a and a0 are relatively prime integers, then gcd(aa0 , b) = gcd(a, b) gcd(a0 , b) for all integers b. (c) An integer a is relatively prime to both integers b and c if and only if a is relatively prime to the product bc. (d) If a, b and n are any integers, then gcd(na, nb) = |n| gcd(a, b). (e) For all integers a, b and c, we have gcd(gcd(a, b), c) = gcd(a, gcd(b, c)). 3