Greatest Common Divisor Blake Thornton Much of this is due directly to Josh Zucker, Paul Zeitz and Harold Reiter. Divisibility 1. How can 48 be built from primes? In what sense is there only one way? How about 234? How can you organize your work to find the prime factors of numbers such as 2008? Solution: 48 =24 · 3 234 =2 · 32 · 13 2008 =23 · 251 2. What are all the divisors of 48? Of 120? Of 2008? How many different ways can you find to organize these answers? Can you tell how many divisors a number will have by looking at it prime factorization? Solution: n 48 = 24 · 3 120 = 23 · 3 · 5 2008 = 23 · 251 Divisors 1, 2, 3, 4, 6, 8, 12, 16, 24, 48 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 1, 2, 4, 8, 251, 502, 1004, 2008 Notice that you can build an array of divisors. Here it is for 48: · 1 = 30 3 = 31 1 = 20 2 = 21 4 = 22 8 = 23 16 = 24 1 2 4 8 16 3 6 12 24 48 This shows that there are 10 divisors of 48. To do this for 120 = 23 · 3 · 5 we would need to build a 3 dimensional array of side length 4 × 2 × 2 so there would be 16 divisors of 120. 3. Make a list of the numbers, 1 through 30, and the number of divisors of that number. You may have heard of this called the tau function, τ (n), the number of divisors of n. What do you notice? 1 In particular, look for differences when the number of divisors is even or odd. Also, look at the sums of divisors (sometimes denoted σ(n)). Also, compare the τ (n), τ (m) and τ (nm) for any n, m. Solution: n τ (n) σ(n) σ(n) − n 1 1 1 0 2 2 3 1 3 2 4 1 4 3 7 3 5 2 6 1 6 4 12 6 7 2 8 1 8 4 15 7 9 3 13 4 10 4 18 8 11 2 12 1 12 6 28 16 13 2 14 1 14 4 24 10 15 4 24 9 16 5 31 15 17 2 18 1 18 6 39 21 19 2 20 1 20 6 42 22 21 4 32 11 22 4 36 14 23 2 24 1 24 8 60 36 25 3 31 6 26 4 42 16 27 4 40 13 28 6 56 28 29 2 30 1 30 8 72 42 Notice that if a number has prime factorization of n = pa11 · · · pamm then τ (n) = n Y (ai + 1) i=1 This means that a number has an odd number of divisors only if each ai is even. The formula τ (ab) = τ (a)τ (b) is valid only when a and b have no common factors. For example, notice τ (2) = 2, τ (4) = 3 but τ (8) = 4. 2 Greatest Common Divisor The greatest common divisor of two numbers is the largest number that divides evenly into both. For example, the greatest common divisor of 10 and 15 is 5: gcd(10, 15) = 5 4. Compute some greatest common divisors. gcd(12, 8) =4 gcd(12, 4) =4 gcd(36, 84) =12 gcd(98, 120) =2 gcd(1232, 24) =8 gcd(2008, 98) =2 gcd(4862, 47320) =26 Explain how you know that you found the greatest common divisor. Euclidean Algorithm (to find GCD) Suppose you want to find gcd(84, 66). First you divide and find the remainder: 84 = 66 · 1 + 18 Then, notice that gcd(84, 66) = gcd(66, 18). The point is that the gcd of two numbers is the same as the gcd of one of the numbers and the remainder (WHY?) Solution: Notice that if gcd(a, b) = d and a = bq +r (with 0 < r < b) then any common divisor of a and b is also a common divisor of r since r = a − bq. Therefore, to find the gcd we just keep dividing making the problem simpler at each stage: 84 = 66 · 1 + 18 66 = 18 · 3 + 12 18 = 12 · 1 + 6 12 = 6 · 2 and therefore gcd(84, 18) = 6. 5. Use the Euclidean Algorithm to find the greatest common divisor for the numbers in Problem 4. 6. Determine if the following statements are true or false: 3 (a) If gcd(a, b) = 1 and gcd(a, c) = 1 then gcd(b, c) = 1. Solution: This is false, you just have to try a few numbers. It is probably most obvious if you choose b = c then gcd(12, 7) = 1 and gcd(12, 7) = 1 but gcd(7, 7) = 1. (b) If gcd(a, b) = 1 and gcd(a, c) = 1 then gcd(a, bc) = 1. Solution: This is true. If p > 1 is a prime that divides both a and bc then p must divide either b or c. Therefore if gcd(a, bc) 6= 1 then we either have gcd(a, b) 6= 1 or gcd(a, c) 6= 1. (c) If gcd(a, b) = 2 and gcd(a, c) = 2 then gcd(b, c) = 2. Solution: This is false, just as before. Just take b = c. (d) If τ (a) = n and τ (b) = m then τ (ab) = mn (see Problem 3). Solution: This is false, as discussed before but it is true if gcd(a, b) = 1. If gcd(a, b) = 1 and p is a prime divisor of ab then p must be a divisor of either a or b but not both. Therefore, any divisor of ab is the product of divisors from a and divisors from b. 7. Least Common Multiple. The least common multiple of two numbers is the smallest number that is a multiple of each. Make a chart of a bunch of numbers, their greatest common divisor and least common multiple. I’ve started your chart for you. Write each of your numbers in its prime factorization (I have not done this for you). a b gcd(a, b) lcm(a, b) 2 3 1 6 4 6 2 12 12 14 2 84 10 15 5 30 2 4 2 4 7 21 7 21 (a) What is 12 · 18? How much is gcd(12, 18) times the least common multiple of 12 and 18? (b) Find a relationship between a, b, gcd(a, b), and lcm(a, b). (c) What is the smallest positive integer that is divisible by each of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10? 4 Solution: The formula is lcm(a, b) = ab gcd(a, b) To find an integer divisible by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, we just have to find the least common multiple of all of these, which is 2520. 8. Pool Table: Imagine a pool table with pockets only in the corners (represent it in graph paper). Start with a ball at the bottom left corner, moving up at an angle of 45◦ . The ball bounces off each side of the rectangle until finally it reaches one of the corners and goes in the pocket. For example, in a 5 × 10 (width 5, height 10), the ball moves as below: When the ball goes into a pocket, we will count that as a bounce on the top/bottom and the sides of the pool table. So, for the 5 × 10 table, the ball bounces on the sides 2 times (one real bounce and one bounce for going in the pocket) and on the top/bottom 2 times (one real bounce and one bounce for going in the pocket). (a) Draw the situation for a 6 × 10 table. How many times does the ball bounce on the top/bottom? How many times does the ball bounce on the sides? Which pocket does the ball land in? Solution: • The ball lands in the upper right corner. • Ball bounces 5 times on sides. • Ball bounces 3 times on top/bottom. (b) Draw a table of various sizes and make a chart listing the dimensions of the table, how many times the ball bounces in total, how many of those bounces are on the left/right sides, how many of those bounces are on the top/bottom sides, and which pocket the ball lands in. Be sure to include at least the following table sizes (and add more tables too!): 5 (Width, Length) Side Bounces Top/Bottom Bounces Pocket (1, 3) 3 1 Top Right (1, 4) 4 1 Top Left (1, 6) 6 1 Top Left (3, 5) 5 3 Top Right (6, 10) 5 3 Top Right (9, 15) 5 3 Top Right (1, 12) 12 1 Top Left (2, 12) 6 1 Top Left (3, 12) 4 1 Top Left (4, 12) 3 1 Top Right (5, 12) 12 5 Top Left (6, 12) 2 1 Top Left (c) Think about greatest common divisor and your table. Why do some of the rows in your table give the same answers? (d) Predict the correct numbers for the table: (Width, Length) Side Bounces Top/Bottom Bounces Pocket (79, 103) 103 79 Top Right (79, 102) 102 79 Top Left (78, 102) 17 13 Top Right Explain your prediction. Prove that you are right. Solution: Lets think about the 6 × 10 case. We can think about the ball bouncing around the table or we can think of the ball traveling in a straight line through reflections of the table (see picture below). 6 In general, consider starting with a table of dimensions a × b. Then, The ball goes in a hole if the line hits the intersection of a vertical and horizontal line. This happens when ma = nb for some m and n. In other words, we are looking for a common multiple of a and b. And, the first time the ball hits a pocket will be when ma = nb is the least common multiple of a and b, or ma = nb = lcm(a, b) = ab gcd(a, b) This gives b gcd(a, b) a n= gcd(a, b) m= and the ball bounces on the sides m times and on the top and bottom n times (remember to include that going in the pocket counts as a bounce). (e) Can you construct a table for which the pool ball bounces on the sides exactly 4 times and on the tops and bottom exactly 8 times? How about bouncing an arbitrary number of times on the sides and an arbitrary number of times on the top/bottom? Solution: We can retrace the steps above. Suppose we want to bounce m times 7 on the sides and n times on the top/bottom. Then, a = n gcd(a, b) b = m gcd(a, b) But, the important thing to note is that we can assume that gcd(a, b) = 1 and that we must have gcd(m, n) = 1 (because of the way m, n are defined). So, if gcd(n, m) = 1 then we can construct a table with the desired bounces. 9. Decanting Problem (Thanks to Harold Reiter). This is a liquid measuring problem that begins with two ungraduated decanters whose integer capacities a and b are given. The problem is to determine the smallest amount of liquid that can be measured and how such amount can be obtained, by a process of filling, pouring, and dumping. Specifically, there are three actions we can take: • fill an empty decanter, • dump out a full decanter, and • pour from one decanter to the other until either the receiving decanter is full or the poured decanter is empty. (a) Let a = 3 and b = 5. See if you can get 1 unit of water. Solution: A little thought and we see that we can fill the 3 unit decanter twice, and dump the 5 unit decanter once to get 1 unit of liquid. Mathematically, 2·3−1·5 = 1. A finite state diagram is helpful to follow the procedure: (0, 0) =⇒ (3, 0) =⇒ (0, 3) =⇒ (3, 3) =⇒ (1, 5) =⇒ (1, 0) where the notation (x, y) means the 3-unit container has x units of liquid and the 5-unit container has y units. (b) Can you find other ways to get 1 unit using decanters of volume 2 and 3? Solution: Here are a few: 2 · 3 − ·5 = 1 −3 · 3 + 2 · 5 = 1 7·3−4·5=1 −8 · 3 + 5 · 5 = 1 12 · 3 − 7 · 5 = 1 (c) Next, suppose the decanters have capacities 5 units and 7 units. How can you make 1 unit of water now? Solution: A little experimentation leads to the conclusion that 1 unit of water can be obtained by filling the 5 unit decanter 3 times, pouring repeatedly from the 8 5 unit to the 7 unit decanter and dumping out the 7 unit decanter twice. A finite state diagram is helpful to follow the procedure: (0, 0) =⇒ (5, 0) =⇒ (0, 5) =⇒ (5, 5) =⇒ (3, 7) =⇒ (3, 0) =⇒ (0, 3) =⇒ (5, 3) =⇒ (1, 7) =⇒ (1, 0) Notice that the procedure includes 3 fills and 2 dumps, with fills and dumps alternating and separated by 4 pours. An arithmetic equation representing this is 3·5−2·7=1 Notice that not only does the arithmetic equation follow from the state diagram, the reverse is also true. That is, given the arithmetic equation, it is an easy matter to construct the state diagram. (d) Find the smallest amount of liquid that you can get using decanters of size 15 and 99. Find a way to get this smallest amount. Solution: An equation can be obtained for any sequence of moves. Such an equation is of the form 15x + 99y = z where exactly one of the integers x and y is negative, and z is the amount obtained. Now notice that the left side is a multiple of 3, so the right side must be also. Thus the least positive amount that can be measured is 3 units. One can also reason as follows: each fill adds a multiple of 3 units of water, each pour leaves the number unchanged, and each dump removes a multiple of three units, so the amount on hand at each stage is a multiple of 3. In fact, the answer is that the least amount that can be measured is the greatest common divisor of the two decanter sizes, and the Euclidean algorithm tells us how to proceed. Suppose c = gcd(a, b). The Euclidean algorithm yields a solution to c = ax + by where x and y are integers exactly one of which is positive and, except in trivial cases, the other is negative. For convenience, we assume x is positive. Then the solution to the decanting problem is to fill the a capacity decanter x times, repeatedly pouring its contents into the b unit decanter. The b unit decanter will be dumped y times, so the total water on hand at the end is the difference ax − by = c. (e) Use the Euclidean Algorithm to find gcd(257, 341). Use your work to solve the decanting problem for decanters of size 257 and 341. Solution: There are two stages. The first stage is a sequence of divisions. The second is a sequence of “unwindings”. We use the division algorithm to get 341 = 1 · 257 + 84 and continue: 341 =1 · 257 + 84 257 =3 · 84 + 5 84 =16 · 5 + 4 5 =1 · 4 + 1 9 and we have gcd(341, 257) = 1. This completes the first stage. Now to unwind, start with the final division scheme write 1 = 5 − 1 · 4 and keep unwinding: 1 =5 − 1 · 4 =5 − 1(84 − 16 · 5) = 17 · 5 − 1 · 84 =17 · (257 − 3 · 84) − 1 · 84 = 17 · 257 − 52 · 84 =17 · 257 − 52 · (341 − 1 · 257) = − 52 · 341 + 69 · 257 (4 = 84 − 16 · 5) (5 = 257 − 3 · 84) (84 = 341 − 1 · 257) Thus, the solution to the decanting problem is to measure out 1 unit of water by filling the 257 unit decanter 69 times, repeatedly pouring its contents into the 341 unit decanter, and, in the process, dumping out the 341 unit decanter 52 times. (f) Use the Euclidean Algorithm to find gcd(102, 78). Use your work to solve the decanting problem for decanters. Solution: gcd(102, 78) =6 6 = − 3 · 102 + 4 · 78 10. Perfect Numbers. A number is perfect if it is equal to the sum of its proper divisors. The smallest perfect numbers are 6, 28 and 496. (a) Write down the prime factorizations of these perfect numbers. Solution: 6 =2 · 22 − 1 28 =22 · 23 − 1 496 =24 · 25 − 1 (b) Check that these numbers really are perfect. (c) Find a pattern of the perfect numbers. See if you can guess the next perfect number. Solution: Here are the smallest perfect numbers: 6 =2 22 − 1 28 =22 23 − 1 496 =24 25 − 1 8128 =26 27 − 1 33, 550, 336 =212 213 − 1 8, 589, 869, 056 =216 217 − 1 10 (d) Prove that the only even perfect numbers are in this pattern (difficult). Solution: We can first prove the following: if p = 2n − 1 is prime then a = 2n−1 (2n − 1) is perfect number. Proof. The first step is to note that σ(p) = p + 1 and σ(2n−1 ) = 2n − 1. Therefore, we have σ(a) =σ(2n−1 )σ(2n − 1) = (2n − 1)(2n − 1 + 1) = 2a Which shows that a is a perfect number. We now prove that if a is an even perfect number then a = 2n−1 (2n − 1) for some n where 2n − 1 is prime. (This is due to Euler.) Proof. Since a is assumed to be even, we can write a = 2n−1 m for some n ≥ 2 and m with m odd. We know that σ(a) = σ(2n−1 m) = σ(2n−1 )σ(m) = (2n − 1)σ(m) Since a is perfect, we know that σ(a) = 2a = 2n m. Putting this all together gives 2n m = (2n − 1)σ(m) and so therefore 2n − 1 divides 2n m and hence 2n − 1 divides m (since it cannot divide 2n ). So, m = (2n − 1)M for some M . Substituting and noticing that m and M are both divisors of m gives 2n m = 2n (2n − 1)M =(2n − 1)σ(m) 2n M =σ(m) ≥ m + M = 2n M Therefore we must have σ(m) = m + M = 2n M . This means that m is prime and its only divisors are itself (m) and 1 (M ). Thus, a = 2n−1 (2n − 1). (e) Find an odd perfect number (this is a famous unsolved problem). Solution: Here are a few known facts. If N is an odd perfect number then: • • • • • N > 10300 The largest prime factor of N is greater than 108 The second largest prime factor of N is greater than 104 The third largest prime factor of N is greater than 100 N has at least 75 prime factors and at least 9 distinct prime factors. 11