Math.3336: Discrete Mathematics Primes and Greatest Common Divisors Instructor: Dr. Blerina Xhabli Department of Mathematics, University of Houston https://www.math.uh.edu/ blerina Email: blerina@math.uh.edu Spring 2019 Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 1/26
Course Information/Office Hours Instructor: Dr. Blerina Xhabli Office hours: TuTh 10:30am 12:00pm (PGH 202) Tutor/Grader: An Vu Office hours: MonWed 2:30pm 4:00pm (Fleming #11) Class meets every TuTh 1:00 pm - 2:30 pm Course webpage: http://www.math.uh.edu/ blerina/ The class webpage contains contact info, office hours, slides from lectures, and important announcements. Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 2/26
Assignments to work on Homework #5 due Thursday, 3/07, 11:59pm No credit unless turned in by 11:59pm on due date Late submissions not allowed, but lowest homework score dropped when calculating grades Homework will be submitted online in your CASA accounts. You can find the instructions on how to upload your homework in our class webpage. Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 3/26
Chapter 4 Number Theory and Cryptography Chapter 4 Overview Divisibility and Modular Arithmetic Section 4.1 Integer Representations and Algorithms Section 4.2 Primes and Greatest Common Divisors Section 4.3 Solving Congruences Section 4.4 Applications of Congruences Section 4.5* Cryptography Section 4.6 Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 4/26
A review on Divisibility and Congruence Modulo Given two integers a and b where a 0, we say a divides b if there is an integer c such that b = ac If a divides b, we write a b; otherwise, a b If a b, a is called a factor of b and b is called a multiple of a. Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 5/26
Properties of Divisibility Theorem 1: If a b and a c, then a (b + c) Theorem 2: If a b, then a bc for all integers c Theorem 3: If a b and b c, then a c Theorem 4: If a b and a c, then a (mb + nc) Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 6/26
The Division Theorem Division theorem: Let a be an integer, and d a positive integer. Then, there are unique integers q, r with 0 r < d such that a = dq + r Here, d is called divisor, and a is called dividend q is the quotient, and r is the remainder. We use the r = a mod d notation to express the remainder The notation q = a div d expresses the quotient Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 7/26
Congruence Modulo a and b are congruent modulo m, a b (mod m) if and only if m (a b) Theorem: a b (mod m) iff a mod m = b mod m If a b (mod m) and c d (mod m) and k Z, then a + c b + d (mod m) a c b d (mod m) ac bd (mod m) a + k b + k (mod m) ak bk (mod m) Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 8/26
Section 4.2 Integer Representations and Algorithms Section Summary Integer Representations Base b Expansions Binary Expansions Octal Expansions Hexadecimal Expansions Base Conversion Algorithm Algorithms for Integer Operations Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 9/26
Section 4.3 Prime Numbers A positive integer p that is greater than 1 and divisible only by 1 and itself is called a prime number. First few primes: 2, 3, 5, 7, 11,... A positive integer that is greater than 1 and that is not prime is called a composite number Example: 4, 6, 8, 9,... Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 10/26
Fundamental Theorem of Arithmetic Fundamental Thm: Every positive integer greater than 1 is either prime or can be written uniquely as a product of primes. This unique product of prime numbers for x is called the prime factorization of x Examples: 12 = 2 2 3 21 = 3 7 99 = 3 3 11 Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 11/26
Determining Prime-ness In many applications, such as crypto, important to determine if a number is prime following thm is useful for this: Theorem: If n is composite, then it has a prime divisor less than or equal to n Proof: Since n is composite, it can be written as n = ab where a > 1 and b > 1. For contradiction, suppose neither a nor b are n, i.e., a > n, b > n Then, n = ab > n 2 = n, a contradiction. Hence, either a n, or b n, and by the Fundamental Thm, is either itself a prime or has a factor less than itself. Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 12/26
Consequence of This Theorem Theorem: If n is composite, then it has a prime divisor n Corollary: If n does not have a prime divisor n, then n is prime. Thus, to determine if n is prime, only need to check if it is divisible by primes n Example: Show that 101 is prime Since 101 < 11, only need to check if it is divisible by 2, 3, 5, 7. Since it is not divisible by any of these, we know it is prime. Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 13/26
Infinitely Many Primes Theorem: There are infinitely many prime numbers. Proof: (by contradiction) Suppose there are finitely many primes: p 1, p 2,..., p n Now consider the number Q = p 1 p 2... p n + 1. Q is either prime or composite Case 1: Q is prime. We get a contradiction, because we assumed only prime numbers are p 1,..., p n Case 2: Q is composite. In this case, Q can be written as product of primes. But Q is not divisible by any of p 1, p 2,..., p n Hence, by Fundamental Thm, not composite Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 14/26
Greatest Common Divisors Suppose a and b are integers, not both 0. Then, the largest integer d such that d a and d b is called greatest common divisor of a and b, written gcd(a,b). Example: gcd(24, 36) = 12 Example: gcd(2 3 5, 2 2 3) = 2 2 Example: gcd(14, 25) = 1 Two numbers whose gcd is 1 are called relatively prime. Example: 14 and 25 are relatively prime Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 15/26
Least Common Multiple The least common multiple of a and b, written lcm(a,b), is the smallest integer c such that a c and b c. Example: lcm(9, 12)= 36 Example: lcm(2 3 3 5 7 2, 2 4 3 3 )= 2 4 3 5 7 2 Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 16/26
Theorem about LCM and GCD Theorem: Let a and b be positive integers. Then, ab = gcd(a, b) lcm(a, b) Proof: Let a = p i 1 1 p i 2 2... pn in and b = p j 1 1 p j 2 2... pn jn Then, ab = p i 1+j 1 1 p i 2+j 2 2... p in +jn n gcd(a, b) = p min(i 1,j 1 ) 1 p min(i 2,j 2 ) 2... p lcm(a, b) = p max(i 1,j 1 ) 1 p max(i 2,j 2 ) 2... p min(in,jn ) n max(in,jn ) n Thus, we need to show i k + j k = min(i k, j k ) + max(i k, j k ) Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 17/26
Proof, cont. Show i k + j k = min(i k, j k ) + max(i k, j k ) Either (i) i k < j k or (ii) i k j k If (i), then min(i k, j k ) = i k and max(i k, j k ) = j k Thus, i k + j k = min(i k, j k ) + max(i k, j k ) If (ii), then min(i k, j k ) = j k and max(i k, j k ) = i k Hence min(i k, j k ) + max(i k, j k ) = i k + j k Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 18/26
Computing GCDs Simple algorithm to compute gcd of a, b: Factorize a as p i1 1 pi2 2... pin n Factorize b as p j1 1 pj2 2... pjn n gcd(a, b) = p min(i1,j1) 1 p min(i2,j2) 2... p min(in,jn ) n But this algorithm is not very practical because prime factorization is computationally expensive! Much more efficient algorithm to compute gcd, called the Euclidian algorithm Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 19/26
Insight Behind Euclid s Algorithm Theorem: Let a = bq + r. Then, gcd(a, b) = gcd(b, r) Proof: We ll show that a, b and b, r have the same common divisors implies they have the same gcd. Suppose d is a common divisor of a, b, i.e., d a and d b By theorem we proved earlier, this implies d a bq Since a bq = r, d r. Hence d is common divisor of b, r. Now, suppose d b and d r. Then, d bq + r Hence, d a and d is common divisor of a, b Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 20/26
Using this Theorem Theorem: Let a = bq + r. Then, gcd(a, b) = gcd(b, r) Theorem suggests following strategy to compute gcd(a, b): Compute r 1 = a mod b (gcd(a, b) = gcd(b, r 1 )) Compute r 2 = b mod r 1 (gcd(a, b) = gcd(r 1, r 2 )) Compute r 3 = r 1 mod r 2 (gcd(a, b) = gcd(r 2, r 3 )) Repeat until remainder becomes 0 (gcd(a, b) = gcd(r n, 0) = r n ) The last non-zero remainder is the gcd of a and b! Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 21/26
Euclidian Algorithm Find gcd of 72 and 20 12 = 72 mod 20 8 = 20 mod 12 4 = 12 mod 8 0 = 8 mod 4 gcd is 4! Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 22/26
Euclidean Algorithm Example Find gcd of 662 and 414 248 = 662 mod 414 166 = 414 mod 248 82 = 248 mod 166 2 = 166 mod 82 0 = 82 mod 2 gcd is 2! Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 23/26
GCD as Linear Combination gcd(a, b) can be expressed as a linear combination of a and b Bezout s Theorem: If a and b are positive integers, then there exist integers s and t such that: gcd(a, b) = s a + t b. This is called the Bezout s identity, and s and t are the Bezout s coefficients. Furthermore, Euclidean algorithm gives us a way to compute these integers s and t Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 24/26
Example Express gcd(252, 198) as a linear combination of 252 and 198 First apply Euclid s algorithm (write a = bq + r at each step): 1 252 = 1 198 + 54 2 198 = 3 54 + 36 3 54 = 1 36 + 18 4 36 = 2 18 + 0 gcd is 18 Now, using (3), write 18 as 54 1 36 Using (2), write 18 as 54 1 (198 3 54) Using (1), we have 54 = 252 1 198, thus: 18 = (252 1 198) 1(198 3 (252 1 198)) Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 25/26
Example, cont. 18 = (252 1 198) 1(198 3 (252 1 198)) Now, let s simplify this: 18 = 252 1 198 1 198 + 3 252 3 198 Now, collect all 252 and 198 terms together: 18 = 4 252 5 198 Trace steps of Euclid s algorithm backwards to derive s, t: gcd(a, b) = s a + t b This is known as the extended Euclidian algorithm Instructor: Dr. Blerina Xhabli, University of Houston Math.3336: Discrete Mathematics Primes and Greatest Common Divisors 26/26