Everything You Need to Know About Modular Arithmetic... Math 135, February 7, 2006 Definition Let m > 0 be a positive integer called the modulus. We say that two integers a and b are congruent modulo m if b − a is divisible by m. In other words, a ≡ b(modm) ⇐⇒ a − b = m · k for some integerk. (1) Note: 1. The notation ?? ≡??(modm) works somewhat in the same way as the familiar ?? =??. 2. a can be congruent to many numbers modulo m as the following example illustrates. Ex. 1 The equation x ≡ 16(mod10) has solutions x = . . . , −24 − 14, −4, 6, 16, 26, 36, 46 . . . . This follows from equation (1) since any of these numbers minus 16 is divisible by 10. So we can write x ≡ · · · − 24 ≡ −14 ≡ −4 ≡ 6 ≡ 16 ≡ 26 ≡ 36 ≡ 46(mod10). Since such equations have many solutions we introduce the notation a(MODm) Definition The symbol a(MODm) (2) denotes the smallest positive number x such that x ≡ a(modm). In other words, a(MODm) is the remainder when a is divided by m as many times as possible. Hence in example 1 we have 6 = 16(MOD10) and 6 = −24(MOD10) etc.... Relation between ”x ≡ b mod m” and ”x = b MOD m” x ≡ b mod m is an EQUIVALENCE relation with many solutions for x while x = b MOD m is an EQUALITY. So one can think of the relationship between the two as follows x = b(MOD m) is the smallest positive solution to the equation x ≡ b(mod m). Since 0 < b(MOD m) < m it is convention to take these numbers as the representatives for the class of numbers x ≡ b(mod m). 1 Ex. 2 The standard representatives for all possible numbers modulo 10 are given by 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 although, for example, 3 ≡ 13 ≡ 23(mod 10), we would take the smallest positive such number which is 3. Inverses in Modular arithmetic We have the following rules for modular arithmetic: Sum rule: IF a ≡ b(mod m) THEN a + c ≡ b + c(mod m). Multiplication Rule: IF a ≡ b(mod m) and if c ≡ d(mod m) THEN ac ≡ bd(mod m). (3) (4) Definition An inverse to a modulo m is a integer b such that ab ≡ 1(mod m). (5) By definition (1) this means that ab − 1 = k · m for some integer k. As before, there are may be many solutions to this equation but we choose as a representative the smallest positive solution and say that the inverse a−1 is given by a−1 = b (MOD m). Ex 3. 3 has inverse 7 modulo 10 since 3 · 7 = 21 shows that 3 · 7 ≡ 1(mod 10) since 3 · 7 − 1 = 21 − 1 = 2 · 10. 5 does not have an inverse modulo 10. If 5 · b ≡ 1(mod 10) then this means that 5 · b − 1 = 10 · k for some k. In other words 5 · b = 10 · k − 1 which is impossible. Conditions for an inverse of a to exist modulo m Definition Two numbers are relatively prime if their prime factorizations have no factors in common. Theorem Let m ≥ 2 be an integer and a a number in the range 1 ≤ a ≤ m − 1 (i.e. a standard rep. of a number modulo m). Then a has a multiplicative inverse modulo m if a and m are relatively prime. Ex 4 Continuing with example 3 we can write 10 = 5 · 2. Thus, 3 is relatively prime to 10 and has an inverse modulo 10 while 5 is not relatively prime to 10 and therefore has no inverse modulo 10. Ex 5 We can compute which numbers will have inverses modulo 10 by computing which are relatively prime to 10 = 5 · 2. These numbers are x = 1, 3, 7, 9. It is easy to see that the following table gives inverses module 10: 2 Table 1: inverses modulo 10 x x−1 MOD 10 1 1 3 7 7 3 9 9 Ex 6: We can solve the equation 3 · x + 6 ≡ 8(mod 10) by using the sum (3) and multiplication (4) rules along with the above table: 3 · x + 6 ≡ 8(mod 10) =⇒ 3 · x ≡ 8 − 6 ≡ 2(mod 10) =⇒ (3−1 ) · 3 · x ≡ (3−1 ) · 2(mod 10) =⇒ x ≡ 7 · 2(mod 10) ≡ 14(mod 10) ≡ 4(mod 10) Final example We calculate the table of inverses modulo 26. First note that 26 = 13 · 2 so that the only numbers that will have inverses are those which are rel. prime to 26...i.e. they contain no factors of 2 or 13: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25. Now we write some multiples of 26 26, 52, 78, 104, 130, 156, 182, 208, 234... A number a has an inverse modulo 26 if there is a b such that a · b ≡ 1(mod 26)or a · b = 26 · k + 1. thus we are looking for numbers whose products are 1 more than a multiple of 26. We create the following table Table 2: inverses modulo 26 x x−1 (MOD m) 1 1 3 9 5 21 7 15 9 3 11 19 15 7 since (using the list of multiples of 26 above) 1 · 1 = 1 = 26 · 0 + 1 3 · 9 = 27 = 26 + 1 5 · 21 = 105 = 104 + 1 7 · 15 = 105 = 104 + 1 11 · 19 = 209 = 208 + 1 17 · 23 = 391 = 15 · 26 + 1 25 · 25 = 625 = 26 · 24 + 1. 3 17 23 19 11 21 5 23 17 25 25 So we can solve y = 17 · x + 12(MOD 26) for x by first considering the congruence equation y ≡ 17 · x + 12(mod 26) and performing the following calculation (similar to ex 6) using the above table: y ≡ 17 · x + 12(mod 26) =⇒ y − 12 ≡ 17 · x(mod 26) =⇒ (17−1 )(y − 12) ≡ (17−1 ) · 17 · x(mod 26) =⇒ (23)(y − 12) ≡ (23) · 17 · x(mod 26) =⇒ 23 · (y − 12) ≡ x(mod 26) We now write x = 23 · (y − 12)(MOD 26). The difference between 23 · (y − 12) ≡ x(mod 26) and x = 23 · (y − 12)(MOD 26) is simply that in the first equation, a choice of y will yield many different solutions x while in the second equation a choice of y gives the value x such that x is the smallest positive solution...i.e. the smallest positive solution to the first equation. 4