Class Notes for Discrete Math I (Rosen) 4.3: PRIMES AND GREATEST COMMON DIVISORS Definition: pZ+ is prime if it has exactly two positive divisors. nZ+ is composite if it has more than two positive divisors. Lemma: If nZ+ is composite, then there is a prime p such that p | n. Theorem (Euclid): There are infinitely many primes. The Fundamental Theorem of Arithmetic: Every positive integer greater than 1 can be uniquely written as the product of prime numbers. Example 1: Find the prime factorization of (a) 6 (b) 10! (c) 437 (d) 521 Theorem: If n is composite, then n has a prime divisor less than or equal to n . Definition: Given a,bZ such that both are not zero. cZ+ is called a common divisor of a and b if c | a and c | b. Let cd(a,b) be the set of all common divisors of a and b. c is called a greatest common divisor of a and b if (1) ccd(a,b) and (2) If dcd(a,b), then d | c. 121 Class Notes for Discrete Math I (Rosen) Theorem: The greatest common divisor of a and b is unique. In set notation, cd(a,b) = { cZ+ | c | a c | b } gcd(a,b) = max{ cZ+ | c | a c | b } Example 3: (a) cd(12,18) = {1, 2, 3, 6} gcd(12,18) = 6 (b) For mZ+, what is gcd(1,m) and gcd(0,m)? (c) For primes p,qP, what is gcd(p,q)? Definition: m,nZ are relatively prime if gcd(m,n) = 1. Example 4: 7 and 15 are relatively prime. Basic Definitions: (a) m div n = m/n (b) m mod n = m – n m/n (c) gcd(m,n) = max{cZ+ | c|m c|n} (d) gcd(n,0) = n for any nZ+ The Division Algorithm: m = n (m div n) + (m mod n). Lemma: If mZ and nZ+, then gcd(m,n) = gcd(n,m mod n). 122 Class Notes for Discrete Math I (Rosen) Example 5: Use the lemma to calculate gcd(294,105). The Extended Euclidean Algorithm: Given mZ and nZ+, there exist unique integers s,tZ such that gcd(m,n) = s m + t n. Procedure: Form the following sequences (three of which are recursively defined). (1) a0 = m, a1 = n, and ai = ai–2 mod ai–1 for i 2. (2) qi = ai–1 div ai for i 1. (3) s0 = 1, s1 = 0, and si = si–2 – qi–1 si–1 for i 2. (4) t0 = 0, t1 = 1, and ti = ti–2 – qi–1 ti–1 for i 2. Sequences terminate for the smallest integer k 2 such that ak+1 = 0, implying that gcd(m,n) = ak, s = sk, and t = tk. 123 Class Notes for Discrete Math I (Rosen) Example 6: Apply the Extended Euclidean Algorithm to m = 2487 and n = 2233. i gcd(ai,ai+1) ai qi si ti 0 1 2 3 4 5 6 7 8 9 124 Class Notes for Discrete Math I (Rosen) Proof of the Extended Euclidean Algorithm: i gcd(ai,ai+1) ai 0 gcd(a0,a1) (=gcd(m,n)) a0 (= m) 1 gcd(a1,a2) a1 (= n) 2 gcd(a2,a3) a2 3 gcd(a3,a4) a3 qi si ti - s0 (=1) t0 (=0) q1 s1 (=0) t1 (=1) q2 s2 t2 q3 s3 t3 k qk gcd(ak,0) ak sk tk Section 4.1, Example 6 (Generalized Shift Cipher): Encryption: Let f (p) = (7p + 3) mod 26. Decryption: Find constants c,d Z26 such that f –1(p) = (c p + d) mod 26. c and d must satisfy (1) 7c 1 (mod 26), and (2) 3c + d 0 (mod 26). i 0 1 2 3 4 gcd(ai,ai+1) gcd(26,7) ai 26 7 qi - si 1 0 ti 0 1 Properties: (a+b) mod m = (a mod m + b mod m) mod m (ab) mod m = (a mod m)(b mod m) mod m a b (mod m) a mod m = b mod m a b (mod m) (a – b) 0 (mod m) 125 Class Notes for Discrete Math I (Rosen) Definition: Given a,bZ such that both are not zero. mZ+ is called a common multiple of a and b if a | m and b | m. Let cm(a,b) be the set of all common multiples of a and b. m is called a least common multiple of a and b if (1) mcm(a,b) and (2) If ncm(a,b), then m | n. Theorem: The least common multiple of a and b is unique. In set notation, cm(a,b) = { mZ+ | a | m b | m } lcm(a,b) = min{ mZ+ | a | m b | m } Example 7: (a) cm(4,6) = {12, 24, 36, 48, …} lcm(4,6) = 12 (b) For mZ+, what is lcm(1,m)? (c) For p,qP, what is lcm(p,q)? Theorem: Let m,nZ+. Then mn = gcd(m,n) lcm(m,n). 126