Modular arithmetic Math 220 Fix an integer m 2, called the modulus. For any other integer a, we can use the division algorithm to write a = qm + r. The reduction of a modulo m is the remainder r resulting from this division; we write a mod m = r or a r (mod m). If a mod m = r and b mod m = r, we say that a is congruent to b modulo m; we write a mod m = b mod m or a b (mod m). Another way of saying this is that a b (mod m) if and only if b a is divisible by m. For each remainder 0 r < m, the set of elements with remainder r is denoted [r] = { a Z : a r (mod m) }. Example. Take m =. There are three possible remainders after division by, namely r = 0, 1, 2. We have [0] = { a Z : a 0 (mod 5) } = {..., 10, 5, 0, 5, 10,...} [1] = { a Z : a 1 (mod 5) } = {...,, 4, 1, 6,,...} [2] = { a Z : a 2 (mod 5) } = {..., 8,, 2, 7, 12,...} [] = { a Z : a (mod 5) } = {..., 7, 2,, 8, 1,...} [4] = { a Z : a 4 (mod 5) } = {..., 6, 1, 4,, 14,...}. For example, 7 1 (mod 5) because they have the same remainder, or equivalently, because 1 ( 7) = 20 is divisible by 5. Arithmetic modulo m. For any integers a, b, we can either perform arithmetic operations first and then reduce modulo m or we can reduce modulo m first and then perform arithmetic operations. We want to verify that we get the same result either way. To do this, we use the division algorithm to write so that a r and b s. Addition yields a = qm + r and b = Qm + s, a + b = (qm + r) + (Qm + s) = (q + Q)m + (r + s), so a + b r + s (mod m). Multiplication yields ab = (qm + r)(qm + s) = (qqm + qs + Qr)m + rs, so ab rs (mod m). As an example, consider the modulus m = 1 and the integers a = 1 and b = 21. We can add them together and reduce modulo 1 to get 1 + 21 = 40 1 (mod 1). Or we can reduce first, then add them together, and then reduce again to get 1 + 21 6 + 8 = 14 1 (mod 1). We can also multiply them and reduce modulo 1 to get 1 21 = (mod 1). Or we can reduce first, then multiply, then reduce again to get 1 21 6 8 48 (mod 1). The important thing is that we get the same remainder through either process.
Solving equations modulo m. 1. Suppose we want to find solutions x to First, we subtract to get 7x + 4 (mod ). 7x 4 5 6 (mod ), so we are trying to solve 7x 6 (mod ). In regular arithmetic, we would divide by 7, but modular division does not always make sense. Instead, by trial and error we can compute all possible 7x modulo. x 0 1 2 4 5 6 7 8 10 7x 0 7 10 6 2 5 1 8 4 Therefore, the only solution to 7x 6 modulo is x 4. 2. To solve the same equation modulo 14, we first subtract, just as before. 7x 4 5 (mod 14), so we want to solve 7x (mod 14). By trial and error again, we compute all possible 7x modulo 14. x 0 1 2 4 5 6 7 8 10 12 1 7x 0 7 0 7 0 7 0 7 0 7 0 7 0 7 This time, there is no solution to 7x (mod 14).. We will find the solutions to x 2x 2 (mod ). Although there are more efficient methods, we proceed again by trial and error, computing x 2, 2x 2, and x modulo. x 0 1 2 4 5 6 7 8 x 2 0 1 4 0 7 7 0 4 1 2x 2 0 2 8 0 5 5 0 8 2 x 0 1 8 0 1 8 0 1 8 Therefore, the solutions to x 2x 2 (mod ) are x 0, 2,, 6. (Notice how there are 4 solutions to a polynomial equation with degree.) Application. One nice application of modular arithmetic is to know when an integer is divisible by,, or. A decimal expansion n = a r... a 2 a 1 a 0 means that n = a 0 + a 1 (10) + a 2 (10 2 ) +... a r (10 r ). Since 10 1 (mod ), we deduce that 10 k 1 k 1 (mod ) for all positive powers k. If we reduce the expression of the decimal expansion modulo, we get n a 0 + a 1 + a 2 +... + a r (mod ). In other words, modulo, n is congruent to the sum of its digits. Since 10 1 (mod ), the same thing is true, namely that n is congruent to the sum of its digits modulo. Since 10 1 (mod ), we know that 10 k ( 1) k 1 (mod ). Therefore, n a 0 a 1 + a 2... + ( 1) r (mod ). In other words, modulo, n is congruent to the alternating sum of its digits. To summarize, an integer n is divisible by or if and only if the sum of its digits is divisible by or. An integer n is divisible by if and only if the alternating sum of its digits is divisible by. For example, for n = 177, the sum of the digits is + 1 + + 7 + 7 = 27, which is divisible by both and. Therefore, n is divisible by. The alternating sum of the digits is 1 + 7 + 7 =. Since this is divisible by, the original number n is also divisible by.
Exercises 1. Find all solutions modulo 14 to the following equations. (a) 5x 4 (mod 14) (b) 6x 5 (mod 14) (c) 6x 6 (mod 14) 2. For each a {0, 1, 2,, 4, 5, 6, 7}, find the solutions modulo 8 to x 2 a (mod 8).. Show that n 7 n is always divisible by 7. (Hint: for each remainder a modulo 7, show that a 7 a 0 (mod 7).) 4. In the integers, we often use two properties: - if kx = ky, then k = 0 or x = y. - if xy = 0, then x = 0 or y = 0. Find some counter-examples to these properties when the arithmetic is done modulo 20. In other words, find some examples of k, x, y {1, 2,..., 18, 1} such that kx ky (mod 20), but x y (mod 20). Also find some examples of x, y 0 such that xy 0 (mod 20). 5. Determine how many times,, and go into the following integers. (a) 21,44,787 (b),16,800 (c),6,6 (d) 4,24,551 6. Fill out the following multiplication table modulo 15. In other words, if the column is a and the row is b, the entry should be ab (mod 15). 1 2 4 5 6 7 8 10 12 1 14 1 2 4 5 6 7 8 10 12 1 14
Answers 1. (a) The only solution is x 12 (mod 14). x 0 1 2 4 5 6 7 8 10 12 1 5x 0 5 10 1 6 2 7 12 8 1 4 (b) There are no solutions. x 0 1 2 4 5 6 7 8 10 12 1 6x 0 6 12 4 10 2 8 0 6 12 4 10 2 8 (c) The solutions are x 1, 8 (mod 14). 2. x 2 0 has two solutions, x 0, 4 (mod 8). x 2 1 has four solutions, x 1,, 5, 7 (mod 8). x 2 4 has two solutions, x 2, 6 (mod 8). And x 2 a has zero solutions for a = 2,, 5, 6, 7. x 0 1 2 4 5 6 7 x 2 0 1 4 1 0 1 4 1. n 7 n is divisible by 7 if and only if n 7 n 0 (mod 7), i.e., if and only if n 7 n (mod 7). There are 7 possible remainders modulo 7 for n. For each of these, we compute n 7 modulo 7. n 0 1 2 4 5 6 n 2 0 1 4 2 2 4 1 n = n 2 n 0 1 1 6 1 6 6 n 4 = n 2 n 2 0 1 2 4 4 2 1 n 7 = n 4 n 0 1 2 4 5 6 The first row and the last row are the same, so n 7 n (mod 7) for all integers n, proving that n 7 n is always divisible by 7. 4. For example, if k = 8, we have that and Also, we have that 8 8 8 8 1 8 18 (mod 20) 8 4 8 8 14 8 1 (mod 20). 8 5 8 10 8 15 0 (mod 20). 21,44,787 5. (a) The sum of the digits is 6, which is divisible by : = 2, 81, 64. The 2,81,64 sum of the new digits is 27, which is divisible by : = 264, 627. The sum 264,627 of the new digits is 27, which is divisible by : = 2, 40. The sum of the 2,40 new digits is 18, which is divisible by : =, 267. The sum of the new digits,267 is 18, which is divisible by : = 6. The sum of the new digits is 12, which 6 is divisible by : = 121. Therefore, 21, 44, 787 is divisible by 5 and divisible by. It is also divisible by 2 = 121. (b) The alternating sum of the digits is 0 0 + 8 6 + 1 + = 0, which is,16,800 divisible by : =, 628, 800. The alternating sum of the new digits is 0 0 + 8 8 + 2 6 + = 1, which is not divisible by. The sum of the new,628,800 digits is 27, which is divisible by : = 40, 200. The sum of the new digits 40,200 is, which is divisible by : = 44, 800. The sum of the new digits is 16, which is not divisible by or. So,, 16, 800 is divisible by and 2. 66 (c) The sum of the digits is 42, which is divisible by : = 22. The alternating sum of the digits is 0, which is divisible by : 22 = 101020. The
alternating sum of the new digits is 7, which is not divisible by. So,, 6, 6 is divisible by and by. 4,24,551 (d) The sum of the digits is 27, which is divisible by : = 4, 804, 8. The sum of the new digits is 6, which is divisible by : 4,804,8 = 5, 871. The sum of 5,871 the new digits is 27, which is divisible by : = 5, 1. The sum of the new 5,1 digits is 27, which is divisible by : = 6, 51. The sum of the new digits is 6,51 21, which is divisible by : = 2, 17. The alternating sum of the new digits is 7 + 1 2 =, which is not divisible by. Therefore, 4, 24, 551 is divisible by 4,, and not divisible by. 6. 1 2 4 5 6 7 8 10 12 1 14 1 1 2 4 5 6 7 8 10 12 1 14 2 2 4 6 8 10 12 14 1 5 7 1 6 12 0 6 12 0 6 12 4 4 8 12 1 5 1 2 6 10 14 7 5 5 10 0 5 10 0 5 10 0 5 10 0 5 10 6 6 12 0 6 12 0 6 12 7 7 14 6 1 5 12 4 10 2 1 8 8 8 1 2 10 4 12 5 1 6 14 7 12 6 0 12 6 0 12 6 10 10 5 0 10 5 0 10 5 0 10 5 0 10 5 7 14 10 6 2 1 5 1 12 8 4 12 12 6 0 12 6 0 12 6 1 1 7 5 1 14 12 10 8 6 4 2 14 14 1 12 10 8 7 6 5 4 2 1