Module NumberTheoryBasics
Module NumberTheoryBasics
Module NumberTheoryBasics
Modular Arithmetic
Given any positive integer n and any integer a, if we divide a by n, we get a quotient q and a remainder r that obey the following relationship:
a = q * n + r, 0 r < n and r is the remainder, q is the quotient When a is positive 0 1 2 n 2n 3n (q-1)n qn r n (q)n r Example:
a = 59; n = 7; 59 = (8)*7 + 3 a = -59; n = 7; -59 = (-9)*7 + 4 59 mod 7 = 3 -59 mod 7 = 4 r = 3; q = 8 r = 4; q = -9
n a (q+1)n
All the numbers marked on the line are actually negative with respect to sign
Modular Arithmetic
Two integers a and b are said to be congruent modulo n, if a mod n = b mod n. This is written as a b mod n.
We say a and b are equivalent to each other in class modulo n
Example:
73 4 mod 23, because 73 mod 23 = 4 = 4 mod 23 21 -9 mod 10, because 21 mod 10 = 1 = -9 mod 10
Example:
73 4 mod 23, then (73 4) mod 23 = 0 73 4 mod 23, then 4 73 mod 23, because 4 mod 23 = 73 mod 23 73 4 mod 23 and 4 96 mod 23, then 73 96 mod 23.
Modular Arithmetic
Now, that we have studied the meaning of equivalency or congruent modulo n, it is see that the mod n operator maps all integers (negative and positive) into the set of integers [0, 1, ., n1]. Example: Class of modulo 15
From the above table, we could say things like -38 22 mod 15 24 54 mod 15 -38 mod 15 = 7 [-38 = (-3)*15 + 7] 24 mod 15 = 9 [24 = (1)*15 + 9] 22 mod 15 = 7 [22 = (1)*15 + 7] 54 mod 15 = 9 [54 = (3)*15 + 9]
Modular Arithmetic
Properties:
(x + y) mod n = (x mod n + y mod n) mod n Example:
Compute: (54 + 49) mod 15 (54 + 49) mod 15 = 103 mod 15 = 13 54 mod 15 = 9 49 mod 15 = 4 (54 mod 15 + 49 mod 15) = 9 + 4 = 13 (54 mod 15 + 49 mod 15) mod 15 = 13 mod 15 = 13
Example:
Compute (42 + 52) mod 15 (42 + 52) mod 15 = 94 mod 15 = 4 42 mod 15 = 12 52 mod 15 = 7 (42 mod 15 + 52 mod 15) = 12 + 7 = 19 (42 mod 15 + 52 mod 15) mod 15 = 19 mod 15 = 4
Modular Arithmetic
Properties:
(x * y) mod n = (x mod n * y mod n) mod n Example:
Compute: (54 * 49) mod 15 (54 * 49) mod 15 = 2646 mod 15 = 6 54 mod 15 = 9 49 mod 15 = 4 (54 mod 15 * 49 mod 15) = 9 * 4 = 36 (54 mod 15 * 49 mod 15) mod 15 = 36 mod 15 = 6
Example:
Compute (42 * 52) mod 15 (42 * 52) mod 15 = 2184 mod 15 = 9 42 mod 15 = 12 52 mod 15 = 7 (42 mod 15 * 52 mod 15) = 12 * 7 = 84 (42 mod 15 * 52 mod 15) mod 15 = 84 mod 15 = 9
Modular Arithmetic
Properties:
(a * b * c) mod n = ( (a mod n) * (b mod n) * (c mod n) ) mod n
(a * b * c) mod n = ( ( ( (a mod n) * (b mod n) ) mod n ) * (c mod n) ) mod n
Modular Arithmetic
Modular Exponentiation
The Right-to-Left Binary Algorithm
Example:
Find the multiplicative inverse of 7 in class modulo 15 Straightforward approach:
Multiply 7 with all the integers [0, 1, , 14] in class modulo 15 There will be only one integer x for which (7*x) modulo 15 = 1
A more efficient approach to find multiplicative inverse in class modulo n is to use the Extended Euclid Algorithm
Property of GCD
For any two integers m and n,
We can write m * x + n * y = GCD (m, n)
x and y are also integers We find x and y through the Extended Euclid algorithm
Iteration 1
Iteration 2
Iteration 4
Iteration 5
-13*53+30*23 = 1 = GCD
23 is the multiplicative inverse of 30 modulo 53 -13 17 is the Multiplicative inverse of 53 modulo 30
STOP!
Iteration 1
Iteration 2