* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Grade 7/8 Math Circles Modular Arithmetic The Modulus Operator
Survey
Document related concepts
Wiles's proof of Fermat's Last Theorem wikipedia , lookup
Location arithmetic wikipedia , lookup
Chinese remainder theorem wikipedia , lookup
Elementary mathematics wikipedia , lookup
List of prime numbers wikipedia , lookup
Collatz conjecture wikipedia , lookup
Transcript
Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Grade 7/8 Math Circles April 3, 2014 Modular Arithmetic The Modulus Operator The modulo operator has symbol “mod”, is written as A mod N , and is read “A modulo N ” or ”A mod N ”. • A is our - what is being divided (just like in division) • N is our (the plural is ) When we divide two numbers A and N , we get a quotient and a remainder. • When we ask for A ÷ N , we look for the quotient of the division. • When we ask for A mod N , we are looking for the remainder of the division. • The remainder A mod N is always an integer between 0 and N − 1 (inclusive) Examples 1. 0 mod 4 = 0 since 0 ÷ 4 = 0 remainder 0 2. 1 mod 4 = 1 since 1 ÷ 4 = 0 remainder 1 3. 2 mod 4 = 2 since 2 ÷ 4 = 0 remainder 2 4. 3 mod 4 = 3 since 3 ÷ 4 = 0 remainder 3 5. 4 mod 4 = since 4 ÷ 4 = 1 remainder 6. 5 mod 4 = since 5 ÷ 4 = 1 remainder 7. 6 mod 4 = since 6 ÷ 4 = 1 remainder 8. 15 mod 4 = 9. * −15 mod 4 = since 15 ÷ 4 = 3 remainder since −15 ÷ 4 = −4 remainder Using a Calculator For really large numbers and/or moduli, sometimes we can use calculators to quickly find A mod N . This method only works if A ≥ 0. Example: Find 373 mod 6 1. Divide 373 by 6 → 2. Round the number you got above down to the nearest integer → 3. Multiply the number you got in Step 2 by your modulus (6) → 4. Subtract the number you got in Step 3 from 373 → Visualizing the Mod Operation To find A mod N , we can either do it algebraically/with a calculator, or we can do it visually, by using a “clock” of numbers 1. Construct a clock with N hours with 0 at the top, going clockwise until N − 1 2. Start at 0 and move around the clock A hours (a) If A is negative, go in counter-clockwise steps (b) If A is positive, go in clockwise steps 3. Whichever “hour” you end up on is the answer. Example Using the below clock, find 3 mod 7, 10 mod 7, −4 mod 7, 17 mod 7 and 23 mod 7. 6 0 1 2 5 4 3 Modular Congruence Whenever two numbers A and B are the “same” modulo N , we say they are congruent modulo N . Mathematically, this is written A ≡ B (mod N ) and it means the following • A and B have the same remainder when divided by N • A mod N = B mod N • N is a factor of the positive difference of B − A • A and B differ by a multiple of N We say “A is congruent to B modulo N ”. Exercises 1. If A ≡ 7 mod 9, (a) Find 5 possible values for A if A ≥ 0 (b) Find 5 possible values for A if A ≤ 0 (c) How many possible values for A are there? (d) Is there anything special about the difference between any two possible values for A? 2. Is −563 ≡ 137 mod 35? Modular Arithmetic Now that we have an understanding of modular congruence, let’s look at how we can use them to find remainders of large sums, differences, and multiplications. This is the study of modular arithmetic. Modular Addition Let’s say you wanted to find (130 + 41) mod 13. You could do this in two ways: • Add 130 to 41, then take its remainder modulo 13. • Individually take the remainder of 130 and 41 modulo 13, then add them. “The remainder of the sum, is the sum of the remainders (modulo N)” Modular Subtraction Let’s say you wanted to find (11 − 45) mod 7. You could do this in two ways: • Subtract 45 from 11, then take its remainder modulo 7. Remember that remainders cannot be negative (to make it positive, add multiples of 7 until it stops being negative). • Individually take the remainder of 45 and 11 modulo 7, then subtract them. “The remainder of the difference, is the difference of the remainders (modulo N)” Modular Multiplication Let’s say you wanted to find (1301 × 130001) mod 13. You could do this in two ways. • Multiply 1301 by 130001, then take its remainder modulo 13. • Individually take the remainder of 1301 and 130001 modulo 13, then multiply them. “The remainder of the product, is the product of the remainders (modulo N)” Modular Powers Let’s say you wanted to find 42008 mod 3. You could do this in two ways. • Calculate 42008 , then take its remainder modulo 3. • Note that 42008 = 4| × ·{z · · × 4}, take the remainder of each modulo 3, then multiply 2008 times them. Exercises 1. Add 135 to 136. What is the remainder of this sum when divided by 5? 2. What is 13 − (−5) mod 6? 3. Find (157 × 375) mod 125. Applications of Congruence We can use congruences with any problems that involve periodic behaviour - when things repeat themselves in a regular pattern. Example: Today is Thursday. 1. What day of the week will it be in 280 days? 2. What day of the week will it be in 365 days? 3. What day of the week will it be in 1000 days? Solution. Since we are dealing with weeks, let’s convert our information into modular congruences. Thursday ≡ 4 (mod 7) a). In 280 days, then, the day will be b). In 365 days, then, the day will be c). In 1000 days, then, the day will be