Chapter 3: Theory of Modular Arithmetic 1 Chapter 3: Theory of Modular Arithmetic SECTION A Introduction to Congruences By the end of this section you will be able to deduce properties of large positive integers apply the rules of congruences prove properties of congruences Large numbers can be difficult to work with. However, often we are only interested in a particular property of a large positive number. For example we might be interested in the following questions: 17 1. What is the last digit of? 171. Is 10 1 divisible by 17? 3. What is the remainder when 1!! 3! 0! is divided by 0? To deal with such questions about large numbers we use modular arithmetic, which is very similar to our normal arithmetic as you will find later in this section. In fact, we already use modular arithmetic every day. Simply being able to use a clock requires us to use modular arithmetic in modulo 1 hours. We don t say thirteen o clock, we start again at one o clock. This is very useful, aside from anything else a 4 hour clock face would be extremely cluttered. The same logic applies here; if we are simply investigating some property of an integer that doesn t require us to know it s precise digits, it is often enough to express it simply as a multiple of some smaller integer, and if necessary, a remainder. Another name for modular arithmetic is arithmetic of remainders because we classify a number according to the remainder when divided by a fixed number called the modulus or modulo. The plural of modulo is moduli. Modular arithmetic converts the infinite number line to a cyclical loop and apart from a few problems with divisibility which we will look at later, it s often an extremely efficient way of analysing large integers. Figure 1 Shows the number line represented as a circle or loop. In modular arithmetic the arithmetic is done in a loop or circle rather than on a number line. In a nutshell, modular arithmetic takes the infinite number line and converts it into a loop and from this loop we can deduce many properties of numbers. For example we can use modular arithmetic to answer divisibility questions such as the following: Show that if the sum of digits of an integer divides into 9 then the integer is divisible by 9. This is an easy check to see if any number is divisible by 9. We will cover this at the end of this section.
Chapter 3: Theory of Modular Arithmetic What day was the 3 rd September 1939? (The day Britain and France declared war on Germany.) Actually modular arithmetic can be used to compute the day of the week of any day in history or in the future. Show that 3 divides 4 n 1 for any natural number n. What are the applications of modular arithmetic? We rely on modular arithmetic more than you might think; your bank uses modular arithmetic to verify credit card transactions, and the bar code on supermarket products is read using modular arithmetic. We will look at an example of a real life application later in this section, but first we need to establish some notation. A1 Definition of Congruence The notation 10 3 mod 7is simply a way of expressing the number 10 in a base modulo of 7, ie; 10 can be expressed as a multiple of 7 (in this case 1 7) with a remainder of 3. It is verbally stated as 10 is congruent to 3 modulo 7. The symbol for congruent to is and modulo n is normally shortened tomod n. Examples of modular arithmetic are: 10 3 mod 7. Modulo 7 is useful for evaluating days of week. For example, if (a) today is Monday then in 10 days time it will be Thursday because 10 3 mod 7 tells us that the quantity contains at least 1 full cycle of seven, ie; Monday to Monday, plus three days. 5 1 mod. Modulo is useful for seeing if the number is odd or even by checking the modular form for a remainder of 0 or 1. 50 mod 4. Modulo 4 can be used to find the time using a 4 hour clock. Suppose it is 9am then in 50 hours time it will be 11am because 50 mod 4 (b) (c) ie, an undefined number of cycles from 9am to 9am, plus hours. We say that 50 is congruent to mod 4. Definition (3.1). Let n be a fixed positive integer and a, b be integers. We say a is congruent to b modulo n which is denoted by a b mod n a b is a multiple of n or there exists an integer k such that a - b = ( k n) The theory of modular arithmetic was developed by one of the greatest mathematician of all time, Gauss:
Chapter 3: Theory of Modular Arithmetic 3 Figure Gauss 1777-1855 Gauss (1777-1855) was one of the three greatest mathematicians of all time, the others being Archimedes and Newton. By the age of eleven Gauss could prove that is irrational. At the age of eighteen he constructed a regular 17 sided polygon with a compass and unmarked straight edge only. Gauss went to the world renowned centre for mathematics Göttingen. Later in life Gauss took up a post at Göttingen and published papers in number theory, infinite series, algebra, astronomy and optics. The unit of magnetic induction is named after Gauss. How do we find the modular form of an integer? a - b = k n to make a the subject gives In the above definition, transposing ( ) a = ( k n) + b Note that b is the remainder after dividing a by n. If the remainder is zero, that is b 0 in the above definition, then we say a is divisible by n or n a. For example: 6 0mod3 because 6 3 0 34 0 mod 17 because 34 17 0 540 0 mod 6 because 540 906 0 We have the following proposition: Proposition (3.). Let a be an integer then a 0 mod n n a In the above example we have 60mod3 3 6. Proof.. Assume a 0mod n. By Definition (3.1): ( mod ) º a - b = ( k n) a b n There exists an integer k such that a - 0 = k n implies that a = kn or n a ( ). Assume n a. This means that there exists an integer c such that Hence 0 ( c n) = a which implies that a - 0 = ( c n) a is a multiple of n so a 0mod n Examples of non-zero remainders are:. 5 divided by 4 gives a remainder of 1 so we can write this as 5 1mod 4
Chapter 3: Theory of Modular Arithmetic 4 10 divided by 7 gives a remainder of 3 so we can write this as 10 3 mod 7 What does 5 1mod 4 mean? 5 divided by 4 gives a remainder of 1. This is an example of clockwork arithmetic. If it is pm and we fast forward by 5 hours then the time will be 3pm because 5 1mod 4. We are not interested in dividing by 1 because the remainder will always be zero, that is for every integer a we have a 0mod1 For congruences we consider the modulus n. a b mod n? How do we know integers a and b exist such that Because by the Division Algorithm (1.7) of chapter 1: Let a and n 1 be two given integers. There exist unique integers q and r such that a = ( n q) + r where 0 r n For example dividing 158 by 10 gives 158 1510 8 which we write as 158 8 mod 10 Similarly we have which is 100 mod 7 100 14 7 Suppose today is Thursday and we are interested in finding what day of the week will be in a 100 days time. How can we find the day of week in 100 days? 7, 14, 1, 8, days after Thursday is a Thursday so we are interested in the remainder of 100 divided by 7 which is. Hence in 100 days time it will be Saturday because 100 mod 7 A Complete System of Residues a = n q + r then In general if ( ) ( mod ) a º r n [r is the remainder of a divided by n] Remember modular arithmetic classifies a number according to the remainder. Since the remainder r can be of any value 0, 1,, 3, 4,, n 1 we conclude that every integer is congruent to one of these. Another name for these remainders is residues. In everyday English language, what does the term residue mean? It means what is left over after something has been removed. What are the residues of modulo 7? The leftovers after dividing any number by 7 can only be 0, 1,, 3, 4, 5 or 6. We normally write these residues in a set 0, 1,, 3, 4, 5, 6. This set 0, 1,, 3, 4, 5, 6 is a complete set of residues modulo 7. What about the residues 7, 8, 9, 10, 11, 1, 13 modulo 7? This is also a complete set of residues modulo 7. However these can all be written as a multiple of 7 plus a remainder between 0 and 6. For example 8 17 1 Writing this in terms of congruences we have 8 1mod7 Example 1 Write two more sets of complete residues modulo 7.
Chapter 3: Theory of Modular Arithmetic 5 We can illustrate modulo 7 as a circle or clock as shown in Fig. 3. We carry out the arithmetic for modulo 7 on this clock with the addition of integers going clockwise and the subtraction of integers going anti-clockwise: Subtract numbers this way. Add numbers this way. Figure 3 We can take integers from 14 onwards, 14, 15, 16, 17, 18, 19, 0. We can also consider negative integers which go anti-clockwise as you can observe from Fig 3. Hence a set of negative integers which form a complete set of residues is 1,, 3, 4, 5, 6, 7 If a set of integers covers all the junctions ( ) around the clock and this set only stops once at each junction then the set is said to be a complete system of residues. The formal definition is: Definition (3.3). The set r, r, r,, r, r is said to form a complete set of residues 1 3 n1 modulo n if every integer is congruent to one and only one r k in the set. This is also called a complete system of residues modulo n. A set of integers is a complete system if it satisfies both these conditions: 1. all stops are covered by the set. the set only stops once at each junction All the above sets: 0, 1,, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 13, 14, 15, 16, 17, 18, 19, 0 and 1,, 3, 4, 5, 6, 7 are a complete system modulo 7. How many of these sets can there be? An infinite number because any set of integers which leave a remainder 0, 1,, 3, 4, 5 and 6 will be a complete system of residues modulo 7. In mathematics we are interested in unique answers if possible. Can we define a unique set of integers which forms a complete system of residues? Yes the least residues or actually the least non-negative residues. The set of integers 0, 1,, 3,, n 1 is called the least non-negative residues modulo n. Hence 0, 1,, 3, 4, 5, 6 is the least non-negative residues modulo 7. Example Write down the complete system of least non-negative residues of: (a) modulo 10 (b) modulo (c) modulo 5 (d) modulo 7 (a) 0, 1,, 3, 4, 5, 6, 7, 8, 9 n
Chapter 3: Theory of Modular Arithmetic 6 (b) 0, 1 (c) 0, 1,, 3, 4 (d) We cannot have modulo of a negative number (see definition (3.1)). Therefore not possible to have least non-negative residues modulo 7. Example 3 In the following, let x be the least non-negative residue modulo n. Find x: 34 x mod 10 100 x mod 9 7 x mod 7 (a) (b) (c) (d) 100 x mod 6 (a) Dividing 34 by 10 yields 34 103 4, we have 34 4 mod 10 so x 4 Note that we have written the number 34 as a multiple of 10 and a remainder of 4. 100 119 1 which means we have a remainder of 1 when (b) Dividing 100 by 9 gives divided by 9: 100 1mod 9 (c) By the Division Algorithm we have 7 47 1: 7 1mod 7 (d) Similarly we have 100 176 : 100 mod 6 implies x 1 implies x 1 implies x If in a set of residues r1, r, r3,, rn 1, rn there are two or more residues congruent to each other modulo, then this system cannot form a complete system of residues. This means the set stops at least twice at a particular junction. For example none of the following are a complete system of residues modulo 5: 10, 15, 0, 5, 30, 1,, 3, 4, 8, 0, 1,, 3, 7 and 0, 1,, 3, 4, 5 Why not? We can illustrate modulo 5 as follows: Figure 4 Modulo 5 clock In the first set 10, 15, 0, 5, 30 all the members are congruent to 0 modulo 5. This means the stops 1,, 3, 4 mod 5 are missing so this set is not a complete system.
Chapter 3: Theory of Modular Arithmetic 7 In the second set, 1,, 3, 4, 8, the stop 0mod5 is missing so cannot be a complete system. In the third set 0, 1,, 3, 7 we have 7 mod 5. This means we have two stops at junction mod5. Remember for a complete system we can only have one stop at each junction. In the final set 0, 1,, 3, 4, 5 we have two stops at 0mod5 because 5 0 mod 5 so this is not a complete system. Proposition (3.4). For arbitrary integers a and b we have a b mod n a and b leave the same non-negative remainder when divided by n. How are we going to prove this result? Since we have the symbol in the statement we need to prove this both ways, and. We use Definition (3.1) and the Division Algorithm. Proof. a b mod n. By the Definition (3.1) :. Assume ( mod ) º a - b = ( k n) a b n There exists an integer k such that a - b = k n (*) ( ) By applying the Division Algorithm (1.7) to a and n we have a = q n + r 0 r < n ( ) 1 1 1 Applying the Division Algorithm to b and n gives b = q n + r 0 r < n ( ) We are required to prove that the remainders are equal, that is r 1 r. Substituting these results, a = ( q n 1 ) + r and 1 ( ) a - b = q n + r - 1 1 ( q n + r ) = ( q - q ) n + ( r -r ) 1 1 b = q n + r, into (*) yields: = kn where k = q -q by (*) 1 This implies that r 1 r 0 which gives r 1 r.. Assume integers a and b leave the same remainder, say r, when divided by n. By the Division Algorithm we have Subtracting these gives From this ( ) 1 a = q n + r 0 r < n 1 1 1 b = q n + r 0 r < n a - b = q n + r -q n -r 1 = q -q n ( ) 1 a - b = q - q n we have a b is a multiple of n which gives
Chapter 3: Theory of Modular Arithmetic 8 a b mod n An example of this result is: 47( mod 10) º 37( mod 10) º 7( mod 10) º 7 ( mod 10) Because 47, 37, 7 or 7 divided by 10 leaves the same remainder 7. We generally write this in compact form as 47 º 37 º 7 º 7 ( mod 10) If an integer a is not congruent to integer b modulo n then we denote this by a b mod n We say a is incongruent to b modulo n. For example 47 6 mod 10, because 47 divided by 10 gives remainder 7 and 6 divided by 10 gives remainder 6. We say 47 is incongruent to 6 modulo 10. A3 Properties of Congruences The congruent symbol can easily be confused with the equal sign and this is because they have very similar properties. Proposition (3.5). We have the following properties of congruences: a a mod n (Reflexive) (i) (ii) If a bmod n then b amod n (Symmetric) (iii) If a bmod n and b cmod n then a cmod n Numerical examples of these results are: 7 7 mod5 (i) (ii) 7 mod 5 7 mod 5 (Transitive) (iii) 7 mod 5, 3 mod 5 implies that 7 3 mod 5 How do we prove the general results given in the above Proposition? By using Definition (3.1) which says: ( mod ) º a - b = ( k n) a b n Proof of (i). We have aa 0 and 0 is a multiple of n because n 0 0 therefore by the definition of congruence a a mod n Proof of (ii). a b mod n We have and this implies there is an integer k such that a - b = ( k n) [a b is a multiple of n] Multiplying this by 1 gives -( a - b) =- k n - = (- ) é - is a multiple of b a k n b a nù êë úû
Chapter 3: Theory of Modular Arithmetic 9 Since b a is a multiple of n so by Definition (3.1) we have our required result: b a mod n Proof of (iii). a b mod n We assume and b cmod n. By using Definition (3.1) there exists integers k and m such that abkn ab is a multiple of n Adding these two gives a bbcknmn From the last line we have a bcmn bc is a multiple of n Simplifying and factorizing c is a multiple of n which implies that a cmod n ac km n. We also need to establish some results which concern addition, subtraction and multiplication in modular arithmetic. We will leave division (or the multiplicative inverse) in modular arithmetic for the next few sections. The next result concerns the addition and multiplication of two congruences. Proposition (3.6). a b mod n c d mod n then If and (i) a + c º ( b + d) ( mod n) (ii) a c º b d ( mod n) Numerical illustrations of this proposition are: 179 mod 11 This proposition says that 179 4159 1 3 mod 11 and 4159 1mod 11 (i) (ii) 1794159 1 mod 11 Notice that we did not need to evaluate the sum 179 4159 or the product 179 4159. See how modular arithmetic subdues these numbers. How do we prove the results of Proposition (3.6)? By using Definition (3.1): Proof of (i). ( mod ) º x - y = ( k n) x y n We can assume a bmod n Similarly with. By this Definition (3.1) there exists an integer k such that a - b = kn [a b is a multiple of n] c d mod n there exists an integer m such that c- d = mn [c d is a multiple of n] Adding these together, a - b = kn and c- d = mn, gives abcdknmn ac bd km n Rearranging and factorizing By the last line we have acb d is a multiple of n so by the above Definition (3.1): acb d mod n
Chapter 3: Theory of Modular Arithmetic 10 This completes our proof. (ii) Similarly we have a - b = kn and c- d = mn where k and m are integers. Multiplying the first a - b = kn by c and multiplying the second c- d = mn by b we have ac bc knc bc bd bmn Adding these gives ac - bc + bc - bd = knc + bmn = 0 ( ) ac - bd = kc + bm n éfactorizingù êë úû Hence ac bd is a multiple of n therefore ac bd mod n What use are these results just established? As a practical application we can apply these results to clockwork arithmetic. Consider the following example: Example 4 If it is 7am, what will be the time in 100 hours? Since we are given that our starting point is 7am so we use modulo 4. What do we need to determine first? Write 100 modulo 4 in terms of the least non-negative residue: 100 4 mod 4 100 44 4 so remainder is 4] [Because Applying the previous property in Proposition (3.6) part (i): If a bmod n and c d mod n then acb d mod n Since we start at 7am so adding 7 7mod 4 and 100 4 mod 4 7 100 7 4 11mod 4 Therefore it will be 11am in 100 hours. gives A4 Applications to Large Integers At the start of this chapter we mentioned that modular arithmetic is used to find properties of large numbers. One application is that we can find the remainder of a large integer when it is divided by an integer. The following example demonstrates this. Example 5 Determine the remainder when 1!! 3! 4! 99! 100! is divided by 0. Recall what n! means: 6! 6543 1 n! n n1 n 31 Adding the first few terms of the given sum we have:
Chapter 3: Theory of Modular Arithmetic 11 1!! 3! 99! 100! 1 3 4 3 5 4 3 6 5 4 3 mod 0 33 0 0 1 640 3 6 0 3 mod 0 33 0 0 0 0 mod 0 Multiple of 0 Multiple of 0 Multiple of 0 Multiple of 0 33 13 mod 0 Hence the remainder is 13 after dividing the large sum 1!! 3! 4! 99! 100! by 0. Note that modular arithmetic tones down large numbers as you can observe from Example 5. Next we look at adding or multiplying the same congruence modulo n to both sides: Corollary (3.7). a b mod n then for any integer c we have If (i) a + c º b + c ( mod n) (ii) ( a c) º ( b c)( mod n) What does this mean? Like the equal sign, adding or multiplying by the same congruence keeps the same congruent relationship. Proof. Applying the previous Proposition (3.6) : If a bmod n and c d mod n then (i) acb d mod n (ii) ac bd mod n with c cmod n then we have both our results: (i) acb cmod n (ii) ac bc mod n A5 Indices of Congruences Which other arithmetic operation do we need to consider? Indices. Next we prove that if a is congruent to b modulo n then taking each of these, a and b, to a natural number index keeps the same congruent relationship. Proposition (3.8). k k a b mod n a º b mod n where k is a natural number. If º ( ) then ( ) A couple of numerical examples of this proposition are: 365 1 mod 7 365 100 1 100 1 mod 7 then 511 then 13 1 511 1 13 mod 14 13 1 mod 14 We did not need to evaluate these large numbers; 100 511 ( 365 has 730 digits and 13 has 5 digits.) How do we prove this Proposition? We repeatedly use Proposition (3.6) (ii): 100 365 or a c º b d ( mod n) 511 13.
Chapter 3: Theory of Modular Arithmetic 1 We are given a º b ( mod n). Multiplying this a b ( mod n) a º b ( mod n) gives a a º b b ( mod n) implies that a º b ( mod n) Repeating this with a º b ( mod n) and a º b ( mod n) yields a a º b b ( mod n) which implies a 3 º b 3 ( mod n) k-1 k- Repeating this until we multiply a º b 1 ( mod n) and a º b ( mod n) : k-1 k-1 k k a a º b b ( mod n) which implies a º b ( mod n) º by the same congruence This completes our proof. We can use all these properties of adding, multiplying and taking powers of congruences to evaluate remainders of numbers. In the next example we demonstrate how modular arithmetic is used to find the last digit of a large number without finding all the digits of the number itself. Example 6 Determine the last digit of 3. The calculator will not show the last digit of this number large (it has 49 digits): 3 3 333 copies 3 because the number is too So how do we evaluate the last digit of 3? The last digit of any integer is the least non-negative residue modulo 10. We are interested in finding the remainder (between 0 and 9) when 3 is divided by 10. This means that we examine modulo 10. Our goal is to find x in the following: 3 x mod 10 [x is the least non-negative residue modulo 10] We know that and 3 9 1mod 10 3 9 because Subtract numbers this way. Add numbers this way. Figure 5 We want to write the index as a multiple of plus remainder because from above we 3 1 mod10 and this makes the arithmetic easier as we have a 1: have 50 1 By using the rules of indices we have
Chapter 3: Theory of Modular Arithmetic 13 Therefore the last digit of 3 3 50 3 3 Using the rules of indices 50 1 50 50 1 3 13 3mod 10 From above 9 3 3 is 3 because the remainder after division by 10 is 3. A6 Divisibility Tests Example 7 4 13 1. Show that What does the notation 4 13 1 mean? 4 goes into 13 1 exactly. Note that 13 1 is a large number ( 13 has 78 digits) which is impossible to write down in decimal format even by using a calculator as most calculators only have a 10 digit display. How are we going to show 4 divides 13 1? Using modular arithmetic with modulo 4. Note that: 13 169 1mod 4 Because 169 44 1 Using the rules of indices we have 35 13 13 Because 35 35 1 Because 13 169 1mod 4 1mod 4 Hence 13 1 1 1 0 mod 4 which means that 4 13 1 13 1 is a multiple of 4 or We did not need to find the actual digits of the large number 13 1 in order to find that 4 goes into this number. The next proposition says that the congruence relationship holds in a polynomial which has integer coefficients. For example 7 6 5 5x 3x x x 3x1 is a polynomial with integer coefficients. Proposition (3.9) m1 m Let Pxc c xc x c x c x be an mth degree polynomial, that is 0 1 m1 c m 0 mod n, where the coefficients c s are integers. If a bmod n Proof. See Exercise 3(a). Example 8 m mod P a P b n then
Chapter 3: Theory of Modular Arithmetic 14 Show that if the sum of digits of an integer divides into 9 then the integer is divisible by 9. This is a very useful result in determining whether a number is divisible by 9 or not. For example, test whether 984567 is divisible by 9: The sum of the digits is 984567 39 and 9 does not divide into 39 therefore 984567 is not divisible by 9. Test 111111111 for divisibility by 9: Similarly adding the digits of 111111111 gives 111111111 9 Clearly 9 divides 9 so 111111111 is divisible by 9. We need to prove this test for divisibility by 9 for every case and not just these two numbers. Proof. Let the integer be N anan 1an aaa 1 0. The sum S of the digits is given by S a a a a a a (*) n n1 n 1 0 We are given that 9 divides into S, that is 9 S or S 0 mod9 ( ) How do we show that this results in 9 divides into the given integer N? N 0 mod9. What does We first write out the integer N and then show that N a a a a aa mean? n n1 n 1 0 It means that the unit s digit is a 0, 10 s digit is a 1, 100 s digit is a, and so on: 10 n 10 n1 10 100 a n an 1 We can write this in expanded form as: N a a a a aa n n1 n 1 0 1 0 10 10 a a 1 a 0 10 1 n n1 n an 10 an1 10 an 10 a 10 a1 10 a0 1 Since we are interested in divisibility by 9 so we use modulo 9. What is 10 modulo 9 equal to? 10 1 mod 9 k k By applying Proposition (3.8) a bmod n implies a b mod n 10 1 1mod 9 3 3 10 1 1mod 9 k k 10 1 1 mod 9 Using these in the congruence below and applying Proposition (3.9): N a a a a aa By (*) n n1 n 1 0 we have n n1 an 10 an1 10 a 10 a1 10 a0 1 mod 9 a 1 a 1 a 1 a 1 a 1 By above results n n1 1 0 an an 1an a a1a0 S 0 mod9 By
Chapter 3: Theory of Modular Arithmetic 15 Hence 9 N because N 0 mod9. In the last calculation we had N S mod 9 which implies N S 9k which we can rearrange as N 9k S. This implies that if 9 N then 9 S. We can restate the above result of Example 8 as Integer is divisible by 9 the sum of the digits is divisible by 9. SUMMARY Modular arithmetic is used to deduce certain properties of large numbers. a b mod n is equivalent to a b is a multiple of n. We say that If a bmod n and c d mod n then 1) acb d mod n, ac bd mod n k k ) a b mod n