Modular Arithmetic claserken July 2016 Contents 1 Introduction 2 2 Modular Arithmetic 2 2.1 Modular Arithmetic Terminology.................. 2 2.2 Properties of Modular Arithmetic.................. 2 2.3 An Interesting Modular Arithmetic Problem............ 3 2.4 Modular Arithmetic Exercises.................... 3 3 The Chinese Remainder Theorem (CRT) 3 3.1 Example 1(With two congruences)................. 3 3.2 Example 2(With three congruences)................ 4 3.3 The Extended Euclidean Algorithm................. 5 1
1 Introduction This is a crash course into modular arithmetic, the Chinese Remainder Theorem, and the extended Euclidean Algorithm. The only things you need to know are algebra and school 5th grade NT. Have fun! 2 Modular Arithmetic I start off with a formal definition and from there I will break it apart and explain it. Formal Definition: a b (mod c) if a b is a multiple of c and a b is a multiple of c if a b (mod c). What I mean here is this: If a b (mod c), then a is b more than some multiple of c. Let me give some examples. 22 2 (mod 10) because 22 = 2+10 2, 28 6 (mod 11) because 28 = 6+11 2, 17 2 (mod 5) because 17 = 2 + 5 3. Also, you could flip each of those statements. By that I mean, since 22 = 2 + 10 2 that means 22 2 (mod 10) and you can apply the same thing to the other examples previously. Additionally, let me introduce some definitions. If you are wondering how to pronounce a b (mod c), it is a is congruent to b modulo c. 2.1 Modular Arithmetic Terminology Residue: In the congruence a b (mod c), b is known as the residue. In modular arithmetic, the residue can be negative. For example, 5 2 (mod 7) because 5 = 2 + 7 1. Modulo: In the congruence a b (mod c), c is known as the modulo. 2.2 Properties of Modular Arithmetic I leave the following properties for the reader to think about. Addition: a b (mod c) = a + d b + d (mod c) Subtraction: a b (mod c) = a d b d (mod c) Multiplication: a b (mod c) = ad bd (mod c) Division: If a = jk, b = jd, and a b (mod c), then k d (mod c gcd(c,j) ) Exponentiation: a b (mod c) = a e b e (mod c) Note that the gcd(a, b) is the greatest integer that divides both a and b. 2
2.3 An Interesting Modular Arithmetic Problem Problem: Prove that a number and the sum of the digits of a number are congruent modulo 3. Proof : Let this number be x. Then, x = a n 10 n + a n 1 10 n 1 + + a 0, where each a i is the corresponding digit to x. Therefore, this problem is equivalent to proving that a n 10 n + a n 1 10 n 1 + + a 0 (mod 3) = a n + a n 1 +... + a 0 (mod 3), but since 10 1 (mod 3), so then the problem is equivalent to a n 1 n + a n 1 1 n 1 + + a 0 (mod 3) = a n + a n 1 +... + a 0 (mod 3), which is obviously true. 2.4 Modular Arithmetic Exercises 1. Write 3 numbers that are congruent to 5 modulo 7. 2. What modulo does a clock work on? 3. Prove that a number and the sum of the digits of a number are congruent modulo 9(Use the same argument as the one I did for modulo 3) 4. Prove that a number and number formed by the last two digits or that number(assume it has at least two digits) are congruent modulo 4 5. Convince yourself that the Properties of Modular Arithmetic are true. 6. Prove that there exists no positive integer solutions to the modular equation x 2 + y 2 3 (mod 4) 7. Prove that n 15 n 5 is divisible by 264 for all integers n 8. Prove that the product of the side lengths of a right triangle is divisible by 60 3 The Chinese Remainder Theorem (CRT) The Chinese Remainder Theorem is a way of solving a set of congruences under a certain condition. I will dive right into an example, as I think that is the easiest to learn the Chinese Remainder Theorem. 3.1 Example 1(With two congruences) Problem: Find all x, such that x 3 (mod 7) and x 2 (mod 5). 3
Solution: We first check that we are able to apply the CRT here. It states that every pair of the modulos have to be relatively prime. In this case, the only modulos are 5 and 7, so the only pair is 5 and 7 and they are relatively prime. Note that if two numbers, a and b are relatively prime, then the gcd(a, b) = 1 and vice versa. Now, we continue with CRT. We start off by writing x like this x = 7a + 5b (The reason we write x like this is a lemma known as Bezout s Lemma, but that is for a different article. You can learn more about it here: https://www.artofproblemsolving.com/wiki/index. php?title=bezout%27s_lemma) realize the residue when x is take (mod 7) is the rightmost number (the 5b) and also realize that the residue when x is taken (mod 5) is the leftmost number (7a). The important takeaway from that realization is this: If I change a that will only affect x modulo 5 and if I change b it will only affect x modulo 7. That means we can work on trying to satisfy one of the problems given congruences without having to worry about messing up the other one, so we continue by trying to make x 3 (mod 7). x is currently 5b (mod 7), which we want to make 3 (mod 7), so we try to find the minimum natural b, such that 5b (mod 7) = 3 (mod 7), by incrementing b by 1 from 1, we get b = 2. Now, we continue by trying to make x 2 (mod 5). x is currently 7a (mod 5), which we want to make 2 (mod 5), so we try to find the minimum natural a, such that 7a (mod 5) = 2 (mod 5), by incrementing a by 1 from 1, we get a = 1. Now, by substituting b = 2 and a = 1, we get x = 17. We are not done yet however, because we could add or subtract 35 = 7 5 to x and it would still satisfy both of the congruences. This means x = 17 + 35y, where y is any integer. Realize that x 17 (mod 35). This means our answer is all x that satisfy x 17 (mod 35). Phew, that was a lot. From the example above, it sounds like CRT is a method of solving congruences. CRT actually only states that there exists x(x is from the above example) The method used to solve the congruences is known as Gauss s Algorithm. 3.2 Example 2(With three congruences) Problem: Find all x, such that x 3 (mod 11), x 6 (mod 7), and x 2 (mod 4). Solution: We first check that we are able to apply CRT here. There are 3 pairs, namely 11 and 7, 11 and 4, and 7 and 4. All of those pairs are relatively prime, so we are able to apply CRT here. Now, we let x = 28a + 44b + 77c(In general, for each of the modulos you multiply the other modulos together and then assign it a variable that hasn t been used) Like in the above example, we can work on trying to satisfy one of the congruences without having to worry about messing up any of the other ones. We work on trying to satisfy x 3 (mod 11) first. Currently, x 28a (mod 11), so we try to finding the smallest positive a such that 28a (mod 11) = 3 (mod 11), or 6a (mod 11) = 3 (mod 11) because 28 6 (mod 11). By incrementing by 1 from 1, we get a = 6. Now 4
we work on trying to satisfy x 6 (mod 7). x is currently 44b (mod 7), so we try the smallest positive integer b such that 44b (mod 7) = 6 (mod 7) = 2b (mod 7) = 6 (mod 7). By incrementing by 1 from 1 we get b = 3. Now we work on trying to satisfy our final congruence, which is x 2 (mod 4). Currently x 77c (mod 4), so we try finding the smallest positive integer c such that 77c (mod 4) = 2 (mod 4) = c (mod 4) = 2 (mod 4). By incrementing by 1 from 1, we get c = 2. Now, we have a = 6, b = 3, and c = 2. This means that x = 454. We are not done yet because we could add or subtract 11 7 4 = from x and x would still satisfy the congruences, this means that x = 454 + 308y. This means x 454 (mod 308) = x 146 (mod 308) 3.3 The Extended Euclidean Algorithm 5