L9 Number Theory
L9 Number Theory
L9 Number Theory
Divisors
DEF: Let a, b and c be integers such that
a = b ·c .
Then b and c are said to divide (or are
factors) of a, while a is said to be a multiple
of b (as well as of c). The pipe symbol “|”
denotes “divides” so the situation is
summarized by:
b|a c|a.
NOTE: Students find notation confusing, and
think of “|” in the reverse fashion, perhaps
confuse pipe with forward slash “/”
Divisors.
Examples
Q: Which of the following is true?
1. 77 | 7
2. 7 | 77
3. 24 | 24
4. 0 | 24
5. 24 | 0
L9 3
Divisors.
Examples
A:
1. 77 | 7: false bigger number can’t divide
smaller positive number
2. 7 | 77: true because 77 = 7 · 11
3. 24 | 24: true because 24 = 24 · 1
4. 0 | 24: false, only 0 is divisible by 0
5. 24 | 0: true, 0 is divisible by every number (0 =
24 · 0)
L9 4
Properties of Divisibility
If a|1, then a = ±1.
L9 6
Prime Numbers
A: 0, and 1 not prime since not positive and
greater or equal to 2
2 is prime as 1 and 2 are only factors
3 is prime as 1 and 3 are only factors.
4,6,8,10 not prime as non-trivially divisible by
2.
5, 7 prime.
9 = 3 · 3 not prime.
Last example shows that not all odd numbers
are prime.
L9 7
Fundamental Theorem of
Arithmetic
THM: Any number n 2 is expressible as
as a unique product of 1 or more prime
numbers.
Note: prime numbers are considered to be
“products” of 1 prime.
We’ll need induction and some more
number theory tools to prove this.
Q: Express each of the following number
as a product of primes: 22, 100, 12, 17
L9 8
Fundamental Theorem of
Arithmetic
A: 22 = 2·11, 100 = 2·2·5·5,
12 = 2·2·3, 17 = 17
Convention: Want 1 to also be expressible as a
product of primes. To do this we define 1 to be
the “empty product”. Just as the sum of nothing
is by convention 0, the product of nothing is by
convention 1.
Unique factorization of 1 is the factorization that
uses no prime numbers at all.
L9 9
Primality Testing
Prime numbers are very important in encryption
schemes. Essential to be able to verify if a
number is prime or not. It turns out that this is
quite a difficult problem. First try:
boolean isPrime(integer n)
if ( n < 2 ) return false
for(i = 2 to n -1)
if( i |n ) // “divides”! not disjunction
return false
return true
Q: What is the running time of this algorithm?
L9 10
Primality Testing
A: Assuming divisibility testing is a basic
operation –so O (1) (this is an invalid
assumption)– then above primality
testing algorithm is O (n).
Q: What is the running time in terms of
the input size k ?
L9 11
Primality Testing
A: Consider n = 1,000,000. The input
size is k = 7 because n was described
using only 7 digits. In general we have
n = O (10k ). Therefore, running time is
O (10k ). REALLY HORRIBLE!
L9 12
Division
Remember long division?
q the
d the 3 quotient
divisor 31 117
93
a the r the
dividend 24 remainder
117 = 31·3 + 24
a = dq + r
L9 13
Division
THM: Let a be an integer, and d be a positive
integer. There are unique integers q, r with r
{0,1,2,…,d-1} satisfying
a = dq + r
The proof is a simple application of long-division.
The theorem is called the division algorithm
though really, it’s long division that’s the
algorithm, not the theorem.
L9 14
Greatest Common Divisor
Relatively Prime
DEF Let a,b be integers, not both zero. The
greatest common divisor of a and b (or
gcd(a,b) ) is the biggest number d which
divides both a and b.
Equivalently: gcd(a,b) is smallest number which
divisibly by any x dividing both a and b.
DEF: a and b are said to be relatively prime if
gcd(a,b) = 1, so no prime common divisors.
L9 15
Greatest Common Divisor
Relatively Prime
Q: Find the following gcd’s:
1. gcd(11,77)
2. gcd(33,77)
3. gcd(24,36)
4. gcd(24,25)
L9 16
Greatest Common Divisor
Relatively Prime
A:
1.gcd(11,77) = 11
2.gcd(33,77) = 11
3.gcd(24,36) = 12
4.gcd(24,25) = 1. Therefore 24 and 25 are
relatively prime.
NOTE: A prime number are relatively prime to
all other numbers which it doesn’t divide.
L9 17
Euclidean algorithm
L9 21
mod function
A: Compute
1. 113 mod 24:
24 113
2. -29 mod 7
L9 22
mod function
A: Compute
1. 113 mod 24: 4
24 113
96
17
2. -29 mod 7
L9 23
mod function
A: Compute
1. 113 mod 24: 4
24 113
96
17
2. -29 mod 7
7 29
L9 24
mod function
A: Compute
1. 113 mod 24: 4
24 113
96
17
2. -29 mod 7
5
7 29
35
6
L9 25
(mod) congruence Formal
Definition
DEF: Let a, a’ be integers and b be a positive
integer. We say that a is congruent to a’
modulo b (denoted by a a’ (mod b) ) iff
b | (a – a’ ).
Equivalently: a mod b = a’ mod b
L9 27
Modular Arithmetic
• Congruence
– a ≡ b mod n says when divided by n that a
and b have the same remainder
– It defines a relationship between all
integers
• a≡a
• a ≡ b then b ≡ a
• a ≡ b, b ≡ c then a ≡ c
Cont.
• addition
– (a+b) mod n ≡(a mod n) + (b mod n)
• subtraction
– a-b mod n ≡ a+(-b) mod n
• multiplication
– a*b mod n
– derived from repeated addition
– Possible: a*b ≡ 0 where neither a, b ≡ 0 mod n
• Example: 2*3 =0 mod 6
Cont.
• Division
– b/a mod n
– multiplied by inverse of a: b/a = b*a-1 mod n
– a-1*a ≡ 1 mod n
– 3-1 ≡7 mod 10 because 3*7 ≡ 1 mod 10
– Inverse does not always exist!
• Only when gcd(a,n)=1
Modular Arithmetic
• An Addition Table in Z12
Plus 0 1 2 3 4 5 6 7 8 9 10 11
0 0 1 2 3 4 5 6 7 8 9 10 11
1 1 2 3 4 5 6 7 8 9 10 11 0
2 2 3 4 5 6 7 8 9 10 11 0 1
3 3 4 5 6 7 8 9 10 11 0 1 2
4 4 5 6 7 8 9 10 11 0 1 2 3
5 5 6 7 8 9 10 11 0 1 2 3 4
6 6 7 8 9 10 11 0 1 2 3 4 5
7 7 8 9 10 11 0 1 2 3 4 5 6
8 8 9 10 11 0 1 2 3 4 5 6 7
9 9 10 11 0 1 2 3 4 5 6 7 8
10 10 11 0 1 2 3 4 5 6 7 8 9
11 11 0 1 2 3 4 5 6 7 8 9 10
Additive Inverse Property
– a + -a = 0
– What is the meaning of -a in Z12?
• If a = 5 then 5 + -5 = 0 translates to
–5 + 7 = 0
• If a = 3 then 3 + -3 = 0 translates to
–3 + 9 = 0
– Then -a can be translated as (n – a)
• The Additive Inverse Property
– The same pattern holds for other n
MOD 4 MOD 9
Plus 0 1 2 3 Plus 0 1 2 3 4 5 6 7 8
0 0 1 2 3 0 0 1 2 3 4 5 6 7 8
1 1 2 3 0 1 1 2 3 4 5 6 7 8 0
2 2 3 0 1 2 2 3 4 5 6 7 8 0 1
3 3 0 1 2 3 3 4 5 6 7 8 0 1 2
4 4 5 6 7 8 0 1 2 3
MOD 5 5 5 6 7 8 0 1 2 3 4
6 6 7 8 0 1 2 3 4 5
Plus 0 1 2 3 4 7 7 8 0 1 2 3 4 5 6
0 0 1 2 3 4 8 8 0 1 2 3 4 5 6 7
1 1 2 3 4 0
2 2 3 4 0 1
3 3 4 0 1 2
4 4 0 1 2 3
Multiplicative Inverse Property
– a * 1/a = 1
– What is the meaning of 1/a in Zn?
• Z12 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
• There are no fractions
• Can we find numbers to multiply a given
element in Z12 such that the product will
be one?
• Definition of division tells us that
if 1/a = k then k * a = 1
• A Multiplication Table in Z12
Times 0 1 2 3 4 5 6 7 8 9 10 11
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10 11
2 0 2 4 6 8 10 0 2 4 6 8 10
3 0 3 6 9 0 3 6 9 0 3 6 9
4 0 4 8 0 4 8 0 4 8 0 4 8
5 0 5 10 3 8 1 6 11 4 9 2 7
6 0 6 0 6 0 6 0 6 0 6 0 6
7 0 7 2 9 4 11 6 1 8 3 10 5
8 0 8 4 0 8 4 0 8 4 0 8 4
9 0 9 6 3 0 9 6 3 0 9 6 3
10 0 10 8 6 4 2 0 10 8 6 4 2
11 0 11 10 9 8 7 6 5 4 3 2 1
Modular Arithmetic
• The Multiplicative Inverse Property: Z12
– Only 1, 5, 7 and 11 have inverses
• 5 and 7 are the inverses of each other
• Both 1 and 11 are their own inverses
• Why don’t the other numbers have inverses?
– Conjectures?
– Test with other mods: Try mods 5, 6, 7, 8, 9, 10
and 11
– But, before you start, look at the table again and
look for more patterns.
Modular Arithmetic
• A Multiplication Table in Z12
Times 0 1 2 3 4 5 6 7 8 9 10 11
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10 11
2 0 2 4 6 8 10 0 2 4 6 8 10
3 0 3 6 9 0 3 6 9 0 3 6 9
4 0 4 8 0 4 8 0 4 8 0 4 8
5 0 5 10 3 8 1 6 11 4 9 2 7
6 0 6 0 6 0 6 0 6 0 6 0 6
7 0 7 2 9 4 11 6 1 8 3 10 5
8 0 8 4 0 8 4 0 8 4 0 8 4
9 0 9 6 3 0 9 6 3 0 9 6 3
10 0 10 8 6 4 2 0 10 8 6 4 2
11 0 11 10 9 8 7 6 5 4 3 2 1
Modular Arithmetic
• The Multiplicative Inverse Property: Zn
– For n = 11, 10, 9, 8, 7, 6, 5,…
• Which numbers have inverses and which do
not?
• Is there a pattern to this?
• Is there a number in every mod that has a
multiplicative inverse (aside from 1)?
• Let’s look…
• A Multiplication Table in Z11
Times 0 1 2 3 4 5 6 7 8 9 10
0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10
2 0 2 4 6 8 10 1 3 5 7 9
3 0 3 6 9 1 4 7 10 2 5 8
4 0 4 8 1 5 9 2 6 10 3 7
5 0 5 10 4 9 3 8 2 7 1 6
6 0 6 1 7 2 8 3 9 4 10 5
7 0 7 3 10 6 2 9 5 1 8 4
8 0 8 5 2 10 7 4 1 9 6 3
9 0 9 7 5 3 1 10 8 6 4 2
10 0 10 9 8 7 6 5 4 3 2 1
• A Multiplication Table in Z10
Times 0 1 2 3 4 5 6 7 8 9
0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9
2 0 2 4 6 8 0 2 4 6 8
3 0 3 6 9 2 5 8 1 4 7
4 0 4 8 2 6 0 4 8 2 6
5 0 5 0 5 0 5 0 5 0 5
6 0 6 2 8 4 0 6 2 8 4
7 0 7 4 1 8 5 2 9 6 3
8 0 8 6 4 2 0 8 6 4 2
9 0 9 8 7 6 5 4 3 2 1
• A Multiplication Table in Z9
Times 0 1 2 3 4 5 6 7 8
0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8
2 0 2 4 6 8 1 3 5 7
3 0 3 6 0 3 6 0 3 6
4 0 4 8 3 7 2 6 1 5
5 0 5 1 6 2 7 3 8 4
6 0 6 3 0 6 3 0 6 3
7 0 7 5 3 1 8 6 4 2
8 0 8 7 6 5 4 3 2 1
• A Multiplication Table in Z8
Times 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 0 2 4 6
3 0 3 6 1 4 7 2 5
4 0 4 0 4 0 4 0 4
5 0 5 2 7 4 1 6 3
6 0 6 4 2 0 6 4 2
7 0 7 6 5 4 3 2 1
• A Multiplication Table in Z7
Times 0 1 2 3 4 5 6
0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6
2 0 2 4 6 1 3 5
3 0 3 6 2 5 1 4
4 0 4 1 5 2 6 3
5 0 5 3 1 6 4 2
6 0 6 5 4 3 2 1
• A Multiplication Table in Z6
Times 0 1 2 3 4 5
0 0 0 0 0 0 0
1 0 1 2 3 4 5
2 0 2 4 0 2 4
3 0 3 0 3 0 3
4 0 4 2 0 4 2
5 0 5 4 3 2 1
• A Multiplication Table in Z5
Times 0 1 2 3 4
0 0 0 0 0 0
1 0 1 2 3 4
2 0 2 4 1 3
3 0 3 1 4 2
4 0 4 3 2 1
• A Multiplication Table in Zn: Summary
Step 1 15 = 1 * 11 + 4 y1 = 1