COMP232 Introduction To Discrete Mathematics Integers and Division
COMP232 Introduction To Discrete Mathematics Integers and Division
1/1
Integers and Division
I Data structures,
I random number generation,
I encryption of data for secure data transmission,
I scheduling,
I etc.
2/1
Division
Definition
For integers a and b with a 6= 0 we define
a divides b iff ∃c ∈ Z b = ac.
a divides b is written as a | b
We call a a factor of b and b a multiple of a.
Example
3 | 15
3 6 | 16
4 | 16
16 6 | 4
3/1
Theorem
3. if a | b and b | c then a | c.
4/1
Partial Proof
3. if a | b and b | c then a | c.
5/1
Prime and composite numbers
Definition
A prime is a positive integer p that has exactly two distinct
positive factors, 1 and p.
A positive integer greater than 1 which is not a prime is called
composite.
Example
Primes: 2, 3, 5, 7, 11, 13, 29, 53, 997, 7951, . . .
Composites: 4 = 2 · 2, 6 = 2 · 3, 35 = 5 · 7, 57 = 3 · 19, etc.
6/1
Fundamental Theorem of Arithmetic
Theorem
Every positive integer x can be written uniquely as a product of
primes, where the prime factors are written in order of their size.
x = p1a1 p2a2 . . . pnan . . .
Example
40 = 2 · 2 · 2 · 5 = 23 · 5
42 = 2 · 3 · 7
780 = 2 · 2 · 3 · 5 · 13 = 22 · 3 · 5 · 13
550 = 2 · 5 · 5 · 11 = 2 · 52 · 11
7/1
Bounded search space
Theorem √
If n is a composite number then n has a factor ≤ n.
Proof.
n is composite, thus by definition there exist a, b ∈ Z with
1 < a < n and 1 < b < n such that n = ab.
√ √
Show that a ≤ n or b ≤ n by contradiction:
√ √
Assume that both a ≥ n and b ≥ n.
√ √
Then n = ab ≥ n n = n, a contradiction.
8/1
Example
n = 311
√ .
311 = 17.6 ≤ 20
Test dividing by 2, 3, 5, 7, 11, 13, 17.
Since none of these divides 311, it is a prime.
Example
n = 253
√ .
253 = 15.9
Test division by 2, 3, 5, 7, 11, 13.
253 = 11*23
9/1
Encryption algorithms
10 / 1
The Division Algorithm
Theorem
Let a be an integer and d a positive integer. Then there exist
unique integers q and r , 0 ≤ r < d, such that
a = dq + r
11 / 1
GCD and LCM
Definition
GCD(a, b), called the greatest common divisor of a and b, is
the largest factor of both a and b, where ab > 0.
When GCD(a, b) = 1, we say that a and b are relatively prime
(or coprime)
GCD(18, 24) = 6
GCD(18, 13) = 1
Definition
LCM(a, b), called the least common multiple of a and b, is the
smallest integer with both a and b as factors.
LCM(8, 6) = 24
LCM(8, 12) = 24
LCM(11, 17) = 11 · 17 = 187
12 / 1
GCD and LCM
Example
780 = 2 · 2 · 3 · 5 · 13 = 22 · 3 · 5 · 13
550 = 2 · 5 · 5 · 11 =2 · 52 · 11
GCD(780, 550) = 2 · 5 = 10
take the factors common to both numbers.
LCM(780, 550) = 22 · 3 · 52 · 11 · 13 = 42900
take all factors in both numbers with highest exponent.
13 / 1
GCD and LCM
If a = p1a1 p2a2 · · · pnan and
b = p1b1 p2b2 · · · pnbn
min(a1 ,b1 ) min(a2 ,b2 ) min(an ,bn )
gcd(a, b) = p1 p2 · · · pn
max(a1 ,b1 ) max(a2 ,b2 ) max(an ,bn )
lcm(a, b) = p1 p2 · · · pn
Note that min(ai , bi ) + max(ai , bi ) = ai + bi , leading to
Theorem
Let a and b be positive integers. Then
ab = gcd(a, b) · lcm(a, b)
Example
GCD(780, 550) = 2 · 5 = 10
780 · 550 = 429000
LCM(780, 550) = 42900
14 / 1
Co-prime integers
Definition
The integers a and b are said to be co-prime or relatively prime
if gcd(a, b) = 1.
Example
6 and 25 are co-prime, as gcd(6, 25) = 1
Example
6 and 27 are not co-prime, since gcd(6, 27) = 3 6= 1
Example
Any two distinct prime numbers are relatively prime
15 / 1
Exercise
Find all pairs of numbers (a, b) such that
gcd(a, b) = 6 and lcm(a, b) = 540.
16 / 1
Exercise solved
min(a2 , b2 ) = 1 max(a2 , b2 ) = 2
min(a3 , b3 ) = 1 max(a3 , b3 ) = 3
min(a5 , b5 ) = 0 max(a5 , b5 ) = 1
{(6, 540), (540, 6), (30, 108), (108, 30)} is the set of all pairs
(a, b).
17 / 1
Eucledean Algorithm — motivation
91 = 14 · 6 + 7
14 = 7 · 2
gcd(287, 91) = gcd(91, 14) = gcd(14, 7) = 7
18 / 1
Eucledean Algorithm
Theorem
Let a = bq + r , where a, b, q, r ∈ Z. Then gcd(a, b) = gcd(b, r ).
19 / 1
Modular Arithmetic
Definition
Let a ∈ Z and m ∈ Z+ with m ≥ 2.
Let a = mq + r and 0 ≤ (a mod m) < m.
a mod m = r = a − m · q
Example
8 mod 7 = 1
12 mod 7 = 5
21 mod 7 = 0
Example
Since the result of the mod operation must be ≥ 0 and < 7,
−3 mod 7 = 4 since −3 = −1 · 7 + 4
−22 mod 6 = 2 since −22 = −4 · 6 + 2
20 / 1
Example of the use of mod
A scheduling problem:
We have processors 1, 2, 3, 4, 5
and jobs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ...
Scheduling: Given a job number, select a processor on which
to execute the job.
Round-robin scheduling:
jobs 1, 6, 11, 16, 21, ... are done on processor 2
jobs 2, 7, 12, 17, 22, ... are done on processor 3
jobs 3, 8, 13, 18, 23, ... are done on processor 4
jobs 4, 9, 14, 19, 24, ... are done on processor 5
jobs 5, 10, 15, 20, 25, ... are done on processor 1
job i is assigned to processor (i mod 5) + 1
21 / 1
Congruences
Definition
Let a and b be integers and m be a positive integer. We say that
a is congruent to b modulo m if m | (a − b).
a ≡ b (modm)
Example
5 | (14 − 9) ⇐⇒ 14 ≡ 9(mod5)
5 | (19 − 9) ⇐⇒ 19 ≡ 9(mod5)
5 | (32 − 12) ⇐⇒ 32 ≡ 12(mod5)
7 | (14 − 7) ⇐⇒ 14 ≡ 7(mod7)
22 / 1
Theorem
23 / 1
Theorem
Proof.
⇒
a ≡ b (modm) ⇒ a − b = km for k ∈ Z (*)
Since a = mq1 + r1 and b = mq2 + r2 for suitable integers
q1 , q2 , r1 , r2 by division algorithm
a − b = (mq1 + r1 ) − (mq2 + r2 ) = m(q1 − q2 ) − (r1 − r2 )
and by (*)
k = q1 − q2 and r1 = r2 and thus a mod m = b mod m
24 / 1
Theorem
Let a and b be integers and m be a positive integer.
a ≡ b (modm) ⇐⇒ (a mod m) = (b mod m)
Proof.
⇐
Let (a mod m) = (b mod m) = r
a mod m = r = a − m · ki from definition of mod and division
algorithm for some ki ∈ Z.
b mod m = r = b − m · kii from definition of mod and division
algorithm for some ki ∈ Z.
a − m · ki = b − m · kii
a − b = ki m − kii m = (ki − kii )m and since ki − kii − k ∈ Z,
a ≡ b (modm) by definition
25 / 1
Theorem
Let a and b be integers and m be a positive integer.
Proof.
If a ≡ b(modm), then m|(a − b) by definition.
Thus there exists k ∈ Z with a − b = km and a = b + km.
Conversely, if there is a k ∈ Z such that a = b + km, then
km = a − b.
26 / 1
Exercise
27 / 1
Theorem
Let m be a positive integer. If a ≡ b (modm) and
c ≡ d (modm) then
a + c ≡ b + d (modm)
a · c ≡ b · d (modm)
28 / 1
Exercise
Show that if a, b, c, and m are integers such that m ≥ 2, c > 0,
and
a ≡ b (mod m), then ac ≡ bc (mod mc).
29 / 1
Proof.
Direct Proof to show that if a, b, c, and m are integers such that
m ≥ 2, c > 0, and a ≡ b (mod m), then ac ≡ bc (mod mc).
Assume
A a ≡ b (mod m)
B a, b, c, and m are integers such that m ≥ 2, c > 0, and
a ≡ b (mod m)
C ac ≡ bc (mod mc)
30 / 1
Proof.
Direct Proof to show that if a, b, c, and m are integers such that
m ≥ 2, c > 0, and a ≡ b (mod m), then ac ≡ bc (mod mc).
31 / 1