Mathematics for Computer Science Exercises for Week 10 Silvio Capobianco Last update: 7 November 2018 Problems from Section 9.1 Problem 9.1. Prove that a linear combination of linear combinations of integers a 0,..., a n is a linear combination of a 0,..., a n. Solution. Suppose we have k 2 linear combinations L i = n j=0 s i,ja j. Given k integers b 1,..., b k, we want to show that L = k i=1 L k is also a linear combination of a 0,..., a n. We can do so by exploiting the commutative, associative, and distributive property: ( k k n ) b i L i = b i s i,j a j i=1 i=1 j=0 ( k n ) = b i s i,j a j = = i=1 j=0 ( n k ) b i s i,j a j j=0 i=1 ( n k ) b i s i,j a j j=0 i=1 which is indeed a linear combination of the a j s. 1
Problem 9.2. A number is perfect if it is equal to the sum of its positive divisors, other than itself. For example, 6 is perfect, because 6 = 1 + 2 + 3. Similarly, 28 is perfect, because 28 = 1 + 2 + 4 + 7 + 14. Explain why 2 k 1 (2 k 1) is perfect when 2 k 1 is prime. Solution. If 2 k 1 is prime, then every positive factor d of n = 2 k 1 (2 k 1) which is different from n is: 1. either a power 2 i of 2 with i [0..k 1] (for i = 0 this also covers the case d = 1), 2. or a product of the form 2 j (2 k 1) with j [0..k 2]. The sum of the factor of the first kind is k 1 i=0 2i = 2 k 1 (remember that k 1 i=0 ai = ak 1 for every a 1) while the sum of the factors of the second a 1 kind is (2 k 1) k 2 j=0 2j = (2 k 1) (2 k 1 1). Then the sum of all positive factors of 2 j (2 k 1), except itself, is: k 1 k 2 2 i + (2 k 1) 2 j = (2 k 1) + (2 k 1)(2 k 1 1) = 2 k 1 (2 k 1) = n. i=0 j=0 Problems for Section 9.2. Problem 9.3. Let x ::= 21212121, y ::= 12121212. Use the Euclidean algorithm to find the GCD of x and y. Hint: Looks scary, but it s not. Solution. The situation is not scary, because 21212121 = 21 1010101 and 12121212 = 12 1010101, which makes computing the GCD much less scary 2
than it seems: gcd(21212121, 12121212) = gcd(12121212, 9090909) = gcd(9090909, 3030303) = gcd(3030303, 0) = 3030303. Problem 9.4. Let x ::= 17 88 31 5 37 2 59 1000 y ::= 19 (922) 37 12 53 3678 59 29. (a) What is gcd(x, y)? (a) What is lcm(x, y)? ( lcm is the least common multiple.) Solution. (a) We use this exercise to introduce an important principle: the greatest common divisor of two numbers, expressed as products of powers of primes, is the product of the common prime factors of the two numbers, each appearing with the lowest exponent of those that appear in the factorizations of the two numbers. Here, the common prime factors are 37 and 59. 37 appears with exponent 2 in x and 12 in y, so it will appear with exponent 2 in gcd(x, y). 59 appears with exponent 1000 in x and 29 in y, so it will appear with exponent 29 in gcd(x, y). In conclusion, gcd(x, y) = 37 2 59 29. (b) For the least common multiple, we use a dual argument: it will be the product of those primes which appear in at least one factorization, each with the highest exponent of those that appear in the factorizations of the two numbers. In our case, lcm(x, y) = 17 88 19 (922) 31 5 37 12 53 3678 59 1000 Alternatively, we can observe that, whatever the positive integers x and y are, the following holds: x y = gcd(x, y) lcm(x, y) 3
Problem 9.5. Show that the following are equivalent: 1. There exists an integer x such that ax = qn + b. 2. gcd(a, n) b. Solution. If ax = qn + b for some integer x, then b = ax qn is a linear combination of a and n, and is thus divisible by gcd(a, n). If b = k gcd(a, n), for a suitable integer k, write gcd(a, n) = sa + tn according to Bézout s theorem: then b = ksa + ktn and we can take x = ks. Problem 9.8. (a) Use the Pulverizer to find integers x, y such that x30 + y22 = gcd(30, 22). (b) Now find integers x, y with 0 y < 30 such that x30 + y22 = gcd(30, 22). Solution. (a) Let us start the Pulverizer: a b rem(a, b) = a qcnt(a, b) b 30 22 8 = 30 22 22 8 6 = 22 2 8 = 22 2 (30 22) = 2 30 + 3 22 8 6 2 = 8 6 = (30 22) ( 2 30 + 3 22) = 3 30 4 22 6 2 0 Then gcd(30, 22) = 2 and we can choose x = 3, y = 4. (b) Of course, gcd(30, 22) 30 22 + 30 22 = gcd(30, 22): we can obtain the 30 22 by decreasing x by 22, and the +30 22 by increasing y by 30. That is, for x = x 22 = 19 and y = y + 30 = 26 we still have gcd(30, 22) = x 30 + y 22. As it turns out, 19 30 = 570 and 26 22 = 572. 4
Problem 9.9. (a) Use the Pulverizer to find gcd(84, 108). (b) Find integers x, y with 0 y < 84 such that x 84 + y 108 = gcd(84, 108). (c) Is there an integer k such that rem(84k, 108) = 1? Solution. (a) Let us start the Pulverizer: a b rem(a, b) = a qcnt(a, b) b 84 108 84 = 84 0 108 108 84 24 = 108 84 84 24 12 = 84 3 24 = 84 3 (108 84) = 4 84 3 108 24 12 0 Then gcd(84, 108) = 12 and we can choose x = 4, y = 3. (b) Of course, gcd(84, 108) 84 108 + 84 108 = gcd(84, 108): we can obtain the 84 108 by decreasing x by 108, and the +84 108 by increasing y by 84. That is, for x = 4 108 = 104 and y = 3 + 84 = 81 we still have gcd(84, 108) = x 84 + y 108. As it turns out, 84 104 = 8736 and 81 108 = 8748. (c) If such k existed, then k 84 qcnt(k 84, 108) 108 = 1 would be a linear combination of 84 and 108, hence be a multiple of gcd(84, 108): this is not the case, as the latter is 12. Problem 9.10. Indicate true or false for the following statements about the greatest common divisor, and provide counterexamples for those that are false. 1. If gcd(a, b) 1 and gcd(b, c) 1 then gcd(a, c) 1. 2. If a bc and gcd(a, b) = 1 then a c. 3. gcd(a n, b n ) = (gcd(a, b)) n. 4. gcd(ab, ac) = a gcd(b, c). 5
5. gcd(1 + a, 1 + b) = 1 + gcd(a, b). 6. If an integer linear combination of a and b equals 1, then so does some integer linear combination of a and b 2. 7. If no integer linear combination of a and b equals 2, then neither does any integer linear combination of a 2 and b 2. Solution. We are making the silent assumption that all the integers considered are positive. 1. False: gcd(4, 6) = 2 and gcd(6, 9) = 3, but gcd(4, 9) = 1. 2. True: this generalizes Lemma 9.4.2 to arbitrary integers. The proof is the same. 3. True: a full proof requires the Fundamental Theorem of Arithmetics, but the exercise does not require to prove true statements, only to provide counterexamples to false ones. 4. True: every common divisor of ab and ac is the product of a divisor of a and a common divisor of b and c, and the maximum such product is a gcd(b, c). 5. False: for a = 4 and b = 6 we have gcd(1 + a, 1 + b) = gcd(5, 7) = 1, but 1 + gcd(4, 6) = 1 + 2 = 3. 6. Yes: if sa + tb = 1 with s and t integers, then gcd(a, b) = 1, so gcd(a, b 2 ) = 1 too, because any prime that divides b 2 also divides b. 7. Yes: in the given hypothesis, gcd(a, b) 3, so gcd(a 2, b 2 ) 9 (simply because, if d n, then d 2 n 2 ) and any positive linear combination of a 2 and b 2 will be 9 or more. Problem 9.12. Here is a game you can analyze with number theory and always beat me. We start with two distinct, positive integers written on a blackboard. Call them a and b. Now we take turns. (I ll let you decide who goes first.) On each turn, the player must write a new positive integer on the board that is 6
the difference of two numbers that are already there. If a player cannot play, then they lose. For example, suppose that 12 and 15 are on the board initially. Your first play must be 3, which is 15 12. Then I might play 9, which is 12 3. Then you might play 6, which is 15 9. Then I can t play, so I lose. (a) Show that every number on the board at the end of the game is a multiple of gcd(a, b). (b) Show that every positive multiple of gcd(a, b) up to max(a, b) is on the board at the end of the game. (c) Describe a strategy that lets you win this game every time. Solution. (a) Let P (n) be the predicate: If the game has reached the nth move, then every number on the board is a multiple of gcd(a, b). We prove by induction that P (n) is true for every n N. Base case: n = 0. Then the only numbers on the board are a and b, which are divisible by gcd(a, b). Induction step: Suppose that, when the game has reached the nth move, all the numbers on the board are multiple of gcd(a, b). Two cases are possible: 1. If no more moves are possible, then P (n + 1) is trivially true as the game doesn t reach the (n + 1)st move. 2. If some moves are possible, then the new number of the board is the difference of some multiple of gcd(a, b), thus still a multiple of gcd(a, b) (b) We first observe that every number of the board must be a linear combination of a and b: equivalently, a multiple of gcd(a, b). If we manage to prove that gcd(a, b) can be put on the board, it will follow that every positive multiple of gcd(a, b) up to max(a, b) can be put on the board: for example, as an element of the sequence max(a, b), max(a, b) gcd(a, b), max(a, b) 2 gcd(a, b),... And this can be done, basically, with the Euclidean algorithm! To fix ideas, suppose a > b. First, build the sequence a, a b, a 2b,..., a qcnt(a, b)b = rem(a, b) = c; 7
next, build the sequence b, b c, b 2c,..., b qcnt(b, c) = rem(b, c) = d, skipping those numbers which have already been reached; and so on, until the Euclidean algorithm would stop. The number reached at that point must be gcd(a, b). (c) Divide max(a, b) by gcd(a, b): the result is the number of numbers on the board at the end of the game, and this is two more than the number of moves, as a and b are on the board from the start. If the result is odd, you take the first move; if the result is even, you leave the first move to me. This ensures that the last move is yours, and you win the game. Problems for Section 9.4 Problem 9.23. Let p be a prime number and a 1,..., a n integers. Prove the following Lemma by induction: Lemma. If p divides a product a 1 a n, then it divides some a i. You may assume the case for n = 2 which was given by Lemma 9.4.2. Be sure to clearly state and label your Induction Hypothesis, Base case(s), and Induction step. Solution. Let P (n) be the following predicate: for every prime p and integers a 1,..., a n, if p a 1 a n, then there exists i [1..n] such that p a i. We want to prove that P (n) is true for every n 1. (For n = 0 the empty product is 1, p does not divide 1, and P (0) is trivially true.) Base case: n = 1. Nothing to say: if p a 1, then p a 1. Induction step: suppose P (n) is true for some n 1. Let a = a 1 a n and b = a n+1. Two cases are possible: 1. p a. Then, by inductive hypothesis, p a i for some i [1..n]. 8
2. p a. Then p b: but b = a n+1. In either case, p a i for some i [1..n + 1]. There are no special hypotheses on n except that n 1, so indeed P (n) implies P (n + 1) for every n 1. By induction, we conclude that P (n) is true for every n 1. 9