Modular Arithmetic
Lecture 8
Def: a b (mod n) iff n|(a - b) iff a mod n = b mod n.
Modular Arithmetic
Lemma: If a c (mod n), and b d (mod n) then
a+b c+d (mod n).
Modular Addition
Lemma: If a c (mod n), and b d (mod n) then
ab cd (mod n).
Modular Multiplication
Exercise
1444 mod 713 =
Exercise
1243 mod 713 =
Application
Why is a number written in decimal evenly divisible by 9 if and
only if the sum of its digits is a multiple of 9?
Hint: 10 1 (mod 9).
Linear Combination vs Common Divisor
Greatest common divisor
d is a common divisor of a and b if d|a and d|b
gcd(a,b) = greatest common divisor of a and b
d is an integer linear combination of a and b if d=sa+tb
spc(a,b) = smallest positive integer linear combination of a and b
Smallest positive integer linear combination
Theorem: gcd(a,b) = spc(a,b)
Theorem: gcd(a,b) = spc(a,b)
Linear Combination vs Common Divisor
For example, the greatest common divisor of 52 and 44 is 4.
And 4 is a linear combination of 52 and 44:
6 · 52 + (−7) · 44 = 4
Furthermore, no linear combination of 52 and 44 is equal
to a smaller positive integer.
To prove the theorem, we will prove:
gcd(a,b) <= spc(a,b)
spc(a,b) <= gcd(a,b)
gcd(a,b) | spc(a,b)
spc(a,b) is a common divisor of a and b
GCD <= SPC
SPC <= GCD
We will prove that spc(a,b) is actually a common divisor of a and b.
Theorem: gcd(a,b) = spc(a,b)
Linear Combination vs Common Divisor
Lemma: p prime and p|a·b implies p|a or p|b.
Cor : If p is prime, and p| a1·a2···am then p|ai for some i.
Lemma. If gcd(a,b)=1 and gcd(a,c)=1, then gcd(a,bc)=1.
Theorem: gcd(a,b) = spc(a,b)
Linear Combination vs Common Divisor
Every integer, n>1, has a unique factorization into primes:
p0 ≤ p1 ≤ ··· ≤ pk
p0 p1 ··· pk = n
Fundamental Theorem of Arithmetic
Example:
61394323221 = 3·3·3·7·11·11·37·37·37·53
Unique Factorization
Claim: There is a unique factorization.
Extended GCD Algorithm
Example: a = 259, b=70
Example: a = 899, b=493
GCD Algorithm
The multiplicative inverse of a number a is another number a’ such that:
a · a’ = 1 (mod n)
Multiplication Inverse
Does every number has a multiplicative inverse in modular arithmetic?
Multiplication Inverse
Nope…
Does every number has a multiplicative inverse in modular arithmetic?
Multiplication Inverse
What is the pattern?
Theorem. If gcd(k,n)=1, then have k’
k·k’ 1 (mod n).
k’ is an inverse mod n of k
Multiplication Inverse
Cancellation
So (mod n) a lot like =.
main diff: can’t cancel
4·2 1·2 (mod 6)
4 1 (mod 6)
No general cancellation
Cor: If i·k j·k (mod n), and gcd(k,n) = 1,
then i j (mod n)
If p is prime & k not a multiple of p, can cancel k. So
k, 2k, …, (p-1)k
are all different (mod p).
So their remainders on division by p are all different (mod p).
Fermat’s Little Theorem
This means that
rem(k, p), rem(2k, p),…,rem((p-1)k, p)
must be a permutation of
1, 2, ···, (p-1)
Fermat’s Little Theorem
1 kp-1 (mod p)
Theorem: If p is prime & k not a multiple of p
Chinese Remainder Theorem
x a1 (mod n1)
x a2 (mod n2)
x ak (mod nk)
Theorem: If n1,n2,…,nk are relatively prime and
a1,a2,…,ak are integers, then
have a simultaneous solution x that is unique
modulo n, where n = n1n2…nk.
Proof of Chinese Remainder Theorem