9/2/2015discrete structures1 let us get into… number theory
TRANSCRIPT
04/19/23 Discrete Structures 2
Introduction to Number TheoryIntroduction to Number Theory
Number theory is about Number theory is about integersintegers and their and their properties.properties.
We will start with the basic principles ofWe will start with the basic principles of
• divisibility,divisibility,• greatest common divisors,greatest common divisors,• least common multiples, andleast common multiples, and• modular arithmeticmodular arithmetic
and look at some relevant algorithms.and look at some relevant algorithms.
04/19/23 Discrete Structures 3
DivisionDivision
If a and b are integers with a If a and b are integers with a 0, we say that 0, we say that a a dividesdivides b if there is an integer c so that b = b if there is an integer c so that b = ac.ac.
When a divides b we say that a is a When a divides b we say that a is a factorfactor of b of b and that b is aand that b is a multiplemultiple of a.of a.
The notationThe notation a | ba | b means that a divides b.means that a divides b.
We writeWe write a a χχ b b when a does not divide bwhen a does not divide b(see book for correct symbol).(see book for correct symbol).
04/19/23 Discrete Structures 4
Divisibility TheoremsDivisibility Theorems
For integers a, b, and c it is true thatFor integers a, b, and c it is true that
• if a | b and a | c, then a | (b + c)if a | b and a | c, then a | (b + c) Example:Example: 3 | 6 and 3 | 9, so 3 | 15.3 | 6 and 3 | 9, so 3 | 15.
• if a | b, then a | bc for all integers cif a | b, then a | bc for all integers c Example:Example: 5 | 10, so 5 | 20, 5 | 30, 5 | 40, …5 | 10, so 5 | 20, 5 | 30, 5 | 40, …
• if a | b and b | c, then a | cif a | b and b | c, then a | c Example:Example: 4 | 8 and 8 | 24, so 4 | 24. 4 | 8 and 8 | 24, so 4 | 24.
Note: a | b is same as writing b/a which means a divides bNote: a | b is same as writing b/a which means a divides b
04/19/23 Discrete Structures 5
The Division AlgorithmThe Division Algorithm
LetLet aa be an integer and be an integer and dd a positive integer.a positive integer.Then there are unique integers Then there are unique integers qq andand rr, with , with 0 0 r < d r < d, such that , such that a = dq + ra = dq + r..
In the above equation, In the above equation, • dd is called the divisor, is called the divisor, • aa is called the dividend, is called the dividend, • qq is called the quotient, where is called the quotient, where q = q = a/da/d • rr is called the remainder, where is called the remainder, where r = a - dq r = a - dq
04/19/23 Discrete Structures 6
The Division AlgorithmThe Division Algorithm
Example:Example:
When we divide 17 by 5, we haveWhen we divide 17 by 5, we have
17 = 517 = 53 + 2.3 + 2.
• 17 is the dividend,17 is the dividend,• 5 is the divisor,5 is the divisor,• 3 is called the quotient, and3 is called the quotient, and• 2 is called the remainder.2 is called the remainder.
04/19/23 Discrete Structures 7
The Division AlgorithmThe Division Algorithm
Another example:Another example:
What happens when we divide -11 by 3 ?What happens when we divide -11 by 3 ?
Note that the remainder cannot be negative.Note that the remainder cannot be negative.
-11 = 3-11 = 3(-4) + 1.(-4) + 1.
• -11 is the dividend,-11 is the dividend,• 3 is the divisor,3 is the divisor,• -4 is called the quotient, and-4 is called the quotient, and• 1 is called the remainder.1 is called the remainder.
04/19/23 Discrete Structures 8
Greatest Common DivisorsGreatest Common DivisorsLet a and b be integers, not both zero.Let a and b be integers, not both zero.The largest integer d such that d | a and d | b is The largest integer d such that d | a and d | b is called the called the greatest common divisorgreatest common divisor of a and b.of a and b.The greatest common divisor of a and b is The greatest common divisor of a and b is denoted by gcd(a, b).denoted by gcd(a, b).
Example 1:Example 1: What is gcd(48, 72) ?What is gcd(48, 72) ?The positive common divisors of 48 and 72 are The positive common divisors of 48 and 72 are 1, 2, 3, 4, 6, 8, 12, and 24, so gcd(48, 72) = 24. 1, 2, 3, 4, 6, 8, 12, and 24, so gcd(48, 72) = 24.
Example 2:Example 2: What is gcd(19, 72) ?What is gcd(19, 72) ?The only positive common divisor of 19 and 72 isThe only positive common divisor of 19 and 72 is1, so gcd(19, 72) = 1. 1, so gcd(19, 72) = 1.
04/19/23 Discrete Structures 9
Greatest Common DivisorsGreatest Common Divisors
Using prime factorizations:Using prime factorizations:
a = pa = p11aa1 1 p p22
aa2 2 … p… pnnaan n , b = p, b = p11
bb1 1 p p22bb2 2 … p… pnn
bbn n ,,
where pwhere p11 < p < p22 < … < p < … < pnn and a and aii, b, bii NN for 1 for 1 i i n n
gcd(a, b) = pgcd(a, b) = p11min(amin(a11, b, b1 1 )) p p22
min(amin(a22, b, b2 2 )) … p… pnnmin(amin(ann, b, bn n ))
Example:Example:
a = 60 a = 60 = =
2222 3 311 5 511
b = 54 b = 54 = =
2211 3 333 5 500
gcd(a, b) gcd(a, b) = =
2211 3 311 5 50 0 = 6 = 6
04/19/23 Discrete Structures 10
Relatively Prime IntegersRelatively Prime IntegersDefinition:Definition:
Two integers a and b are Two integers a and b are relatively primerelatively prime if if gcd(a, b) = 1.gcd(a, b) = 1.
Examples:Examples:
Are 15 and 28 relatively prime?Are 15 and 28 relatively prime?Yes, gcd(15, 28) = 1.Yes, gcd(15, 28) = 1.Are 55 and 28 relatively prime?Are 55 and 28 relatively prime?Yes, gcd(55, 28) = 1.Yes, gcd(55, 28) = 1.Are 35 and 28 relatively prime?Are 35 and 28 relatively prime?No, gcd(35, 28) = 7.No, gcd(35, 28) = 7.
04/19/23 Discrete Structures 11
Relatively Prime IntegersRelatively Prime Integers
Definition:Definition:
The integers aThe integers a11, a, a22, …, a, …, ann are are pairwise pairwise
relatively primerelatively prime if gcd(aif gcd(aii, a, ajj) = 1 whenever 1 ) = 1 whenever 1
i < j i < j n. n.
Examples:Examples:
Are 15, 17, and 27 pairwise relatively prime?Are 15, 17, and 27 pairwise relatively prime?No, because gcd(15, 27) = 3.No, because gcd(15, 27) = 3.
Are 15, 17, and 28 pairwise relatively prime?Are 15, 17, and 28 pairwise relatively prime?Yes, because gcd(15, 17) = 1, gcd(15, 28) = 1 Yes, because gcd(15, 17) = 1, gcd(15, 28) = 1 and gcd(17, 28) = 1.and gcd(17, 28) = 1.
04/19/23 Discrete Structures 12
Least Common MultiplesLeast Common MultiplesDefinition:Definition:
TheThe least common multipleleast common multiple of the positive of the positive integers a and b is the smallest positive integers a and b is the smallest positive integer that is divisible by both a and b.integer that is divisible by both a and b.
We denote the least common multiple of a and We denote the least common multiple of a and b by lcm(a, b).b by lcm(a, b).
Examples:Examples:
lcm(3, 7) lcm(3, 7) ==
2121
lcm(4, 6) lcm(4, 6) ==
1212
lcm(5, 10) lcm(5, 10) ==
1010
04/19/23 Discrete Structures 13
Least Common MultiplesLeast Common Multiples
Using prime factorizations:Using prime factorizations:
a = pa = p11aa1 1 p p22
aa2 2 … p… pnnaan n , b = p, b = p11
bb1 1 p p22bb2 2 … p… pnn
bbn n ,,
where pwhere p11 < p < p22 < … < p < … < pnn and a and aii, b, bii NN for 1 for 1 i i n n
lcm(a, b) = plcm(a, b) = p11max(amax(a11, b, b1 1 )) p p22
max(amax(a22, b, b2 2 )) … p… pnnmax(amax(ann, b, bn n ))
Example:Example:
a = 60 a = 60 = =
2222 3 311 5 511
b = 54 b = 54 = =
2211 3 333 5 500
lcm(a, b) lcm(a, b) = =
2222 3 333 5 51 1 = 4275 = 540 = 4275 = 540
04/19/23 Discrete Structures 14
GCD and LCMGCD and LCM
a = 60 a = 60 = =
2222 3 311 5 511
b = 54 b = 54 = =
2211 3 333 5 500
lcm(a, b) lcm(a, b) = =
2222 3 333 5 51 1 = 540 = 540
gcd(a, b) gcd(a, b) = =
2211 3 311 5 50 0 = 6 = 6
Theorem: ab Theorem: ab ==
gcd(a,b)lcm(a,gcd(a,b)lcm(a,b)b)
04/19/23 Discrete Structures 15
Modular ArithmeticModular Arithmetic
Let a be an integer and m be a positive integer.Let a be an integer and m be a positive integer.We denote by We denote by a mod ma mod m the remainder when a the remainder when a is divided by m.is divided by m.
Examples:Examples:
9 mod 4 9 mod 4 ==
11
9 mod 3 9 mod 3 ==
00
9 mod 10 9 mod 10 ==
99
-13 mod 4 -13 mod 4 ==
33
04/19/23 Discrete Structures 16
CongruencesCongruences
Let a and b be integers and m be a positive Let a and b be integers and m be a positive integer. We say that integer. We say that a is congruent to b a is congruent to b modulo mmodulo m if if m divides a – b.m divides a – b.
We use the notation We use the notation a a b (mod m) b (mod m) to indicate to indicate that a is congruent to b modulo m.that a is congruent to b modulo m.
In other words:In other words:a a b (mod m) if and only if b (mod m) if and only if a mod m = b mod a mod m = b mod mm. .
04/19/23 Discrete Structures 17
CongruencesCongruencesExamples:Examples:Is it true that 46 Is it true that 46 68 (mod 11) ? 68 (mod 11) ?Yes, because 11 | (46 – 68).Yes, because 11 | (46 – 68).Is it true that 46 Is it true that 46 68 (mod 22)? 68 (mod 22)?Yes, because 22 | (46 – 68).Yes, because 22 | (46 – 68).For which integers z is it true that z For which integers z is it true that z 12 (mod 12 (mod 10)?10)?It is true for any zIt is true for any z{…,-28, -18, -8, 2, 12, 22, 32, {…,-28, -18, -8, 2, 12, 22, 32, …}…}
Theorem:Theorem: Let m be a positive integer. The Let m be a positive integer. The integer a is congruent to b modulo m if and only integer a is congruent to b modulo m if and only if there is an integer k such that a = b+ km.if there is an integer k such that a = b+ km.
04/19/23 Discrete Structures 18
CongruencesCongruences
Theorem:Theorem: Let m be a positive integer. Let m be a positive integer. If a If a b (mod m) and c b (mod m) and c d (mod m), then d (mod m), then a + c a + c b + d (mod m) and ac b + d (mod m) and ac bd (mod m). bd (mod m).Proof:Proof: We know that a We know that a b (mod m) and c b (mod m) and c d (mod m) d (mod m) implies that there are integers s and t with implies that there are integers s and t with b = a + sm and d = c + tm. b = a + sm and d = c + tm. Therefore,Therefore,b + d = (a + sm) + (c + tm) = (a + c) + m(s + t) b + d = (a + sm) + (c + tm) = (a + c) + m(s + t) andandbd = (a + sm)(c + tm) = ac + m(at + cs + stm).bd = (a + sm)(c + tm) = ac + m(at + cs + stm).Hence, a + c Hence, a + c b + d (mod m) and ac b + d (mod m) and ac bd (mod bd (mod m).m).
04/19/23 Discrete Structures 19
CongruencesCongruences
Theorem:Theorem: Let m be a positive integer. a Let m be a positive integer. a b (mod b (mod m) iff a mod m = b mod m.m) iff a mod m = b mod m.
Proof:Proof: Let a = mq1 + r1, and b = mq2 + r2.Let a = mq1 + r1, and b = mq2 + r2.
If If a mod m = b mod m a mod m = b mod m r1 = r2, r1 = r2,
thereforethereforea – b = m(q1 – q2), so ma – b = m(q1 – q2), so m | | (a-b) which means (a-b) which means
m m divides a-b.divides a-b.By the definition of congruence it follows By the definition of congruence it follows
that that a a b (mod m). b (mod m).
04/19/23 Discrete Structures 20
The Euclidean Algorithm The Euclidean Algorithm
TheThe Euclidean AlgorithmEuclidean Algorithm finds the finds the greatest greatest common divisorcommon divisor of two integers a and b. of two integers a and b.
For example, if we want to find gcd(287, 91), For example, if we want to find gcd(287, 91), we we dividedivide 287 by 91:287 by 91:First, divide the larger of the two integers,287 First, divide the larger of the two integers,287 by the smaller, 91 to obtainby the smaller, 91 to obtain
287 = 91287 = 913 + 143 + 14Now consider the remainder, 14 and the Now consider the remainder, 14 and the smaller, 91smaller, 91
Consequently, gcd(287, 91) = gcd(91, 14).Consequently, gcd(287, 91) = gcd(91, 14).
04/19/23 Discrete Structures 21
The Euclidean Algorithm The Euclidean Algorithm
In the next step, we divide 91 by 14:In the next step, we divide 91 by 14:
91 = 1491 = 146 + 76 + 7
This means that gcd(91, 14) = gcd(14, 7).This means that gcd(91, 14) = gcd(14, 7).
So we divide 14 by 7:So we divide 14 by 7:
14 = 714 = 72 + 02 + 0
We find that 7 | 14, and thus gcd(14, 7) = 7.We find that 7 | 14, and thus gcd(14, 7) = 7.
Therefore, Therefore, gcd(287, 91) = 7.gcd(287, 91) = 7.
The Euclidean Algorithm The Euclidean Algorithm
The Euclidean algorithm is based on the The Euclidean algorithm is based on the following result about greatest common following result about greatest common divisors and the division algorithm.divisors and the division algorithm.
Let Let a a = = bq bq + + rr, where , where a, b, qa, b, q, and , and r r are integers. are integers. Then gcdThen gcd(a, b) (a, b) = gcd= gcd(b, r)(b, r)..
04/19/23 Discrete Structures 22
04/19/23 Discrete Structures 23
The Euclidean Algorithm The Euclidean Algorithm
InIn pseudocodepseudocode, the algorithm can be , the algorithm can be implemented as follows: implemented as follows:
procedureprocedure gcd(a, b: positive integers) gcd(a, b: positive integers)x := ax := ay := by := bwhilewhile y y 0 0beginbegin
r := x r := x modmod y yx := yx := yy := ry := r
endend {x is gcd(a, b)}{x is gcd(a, b)}
04/19/23 Discrete Structures 24
Tree DiagramsTree DiagramsHow many bit strings of length four do not have How many bit strings of length four do not have two consecutive 1s?two consecutive 1s?
Task 1Task 1 Task 2Task 2 Task 3Task 3 Task 4Task 4(1(1stst bit) bit) (2(2ndnd bit) bit) (3(3rdrd bit) bit) (4(4thth bit) bit)
00
0000
00
1111
0011 00 00
11
11 0000 00
1111
00There are 8 strings.There are 8 strings.
04/19/23 Discrete Structures 25
The Pigeonhole PrincipleThe Pigeonhole PrincipleThe pigeonhole principle:The pigeonhole principle: If (k + 1) or more If (k + 1) or more objects are placed into k boxes, then there is objects are placed into k boxes, then there is at at leastleast one box containing two or more of the one box containing two or more of the objects.objects.
Example 1:Example 1: If there are 11 players in a soccer If there are 11 players in a soccer team that wins 12-0, there must be at least one team that wins 12-0, there must be at least one player in the team who scored at least twice.player in the team who scored at least twice.
Example 2:Example 2: If you have 6 classes from Monday If you have 6 classes from Monday to Friday, there must be at least one day on to Friday, there must be at least one day on which you have at least two classes.which you have at least two classes.
04/19/23 Discrete Structures 26
The Pigeonhole PrincipleThe Pigeonhole Principle
The generalized pigeonhole principle:The generalized pigeonhole principle: If N If N objects are placed into k boxes, then there is objects are placed into k boxes, then there is at at leastleast one box containing at least one box containing at least N/kN/k of the of the objects.objects.
Example 1:Example 1: In our 60-student class, at least 12 In our 60-student class, at least 12 students will get the same letter grade (A, B, C, students will get the same letter grade (A, B, C, D, or F).D, or F).
04/19/23 Discrete Structures 27
The Pigeonhole PrincipleThe Pigeonhole Principle
Example 2:Example 2: What is the minimum number of What is the minimum number of people among 50 people who were born in people among 50 people who were born in the same month?the same month?
Solution: Solution: The minimum number of people The minimum number of people among 50 people who were born in the same among 50 people who were born in the same month is such that month is such that N/12N/12. .
50/1250/12 = 5 = 5