Greatest Common Divisor Chap. 4.3 - Greatest Common Divisor Definition: Let a and B Be Integers, Not Both Zero

Greatest Common Divisor Chap. 4.3 - Greatest Common Divisor Definition: Let a and B Be Integers, Not Both Zero

Announcements CompSci 230 Discrete Math for Computer Science • Homework 4 out October 22, 2013 Prof. Rodger Slide ideas from Rosen and Benjamin 1 2 Chap. 4.3 - Greatest Common Divisor Chap. 4.3 - Greatest Common Divisor Definition: Let a and b be integers, not both zero. Definition: Let a and b be integers, not both zero. The largest integer d such that d | a and also d | b The largest integer d such that d | a and also d | b is called the greatest common divisor of a and b. is called the greatest common divisor 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). Examples: Examples: gcd(12, 30) = 6 gcd(12, 30) = 6 gcd(12, -30) = 6 gcd(12, -30) = 6 gcd(16, 9) = 1 relatively prime gcd(16, 9) = 1 relatively prime gcd(7, 63) = 7 gcd(7, 63) = 7 gcd(7, 0) = 7 3 gcd(7, 0) = 7 4 Greatest Common Divisor Greatest Common Divisor Definition: The integers a and b are relatively prime if Definition: The integers a and b are relatively prime if their greatest common divisor is . their greatest common divisor is . Example: Example: Definition: The integers a1, a2, …, an are pairwise Definition: The integers a1, a2, …, an are pairwise relatively prime if gcd(ai, aj)= whenever i j n. relatively prime if gcd(ai, aj)= whenever i j n. Example: Are and Example: Are and Solution: Yes Yes Example: Are Example: Are Solution: No, No, 5 6 What numbers can be created using What numbers can be created using 12 and 30 as building blocks? 12 and 30 as building blocks? • That means 12s + 30t • That means 12s + 30t • Can you create any positive integer using • Can you create any positive integer using this formula? this formula? • Can you create 4? • Can you create 4? – 4 = 12x + 30 y 4 = 12s + 30 t – = 6(2x + 5y) = 6(2s + 5t) – NO, must be a multiple of 6 NO, must be a multiple of 6 7 8 Can you create 6 using 12s + 30t? Can you create 6 using 12s + 30t? 6 = 12s + 30 t 6 = 12s + 30 t = 12(3) + 30(-1) = 36 – 30 = 6, yes! = 12(3) + 30(-1) = 36 – 30 = 6, yes! Can you create any multiple of 6 using 12 and 30? Can you create any multiple of 6 using 12 and 30? Yes Yes 12(3m) + 30(-m) = 6m 12(3m) + 30(-m) = 6m 9 10 Can you create any number using Can you create any number using 16 and 9 as building blocks? 16 and 9 as building blocks? 16s + 9t 16s + 9t Can you create the number 1? Can you create the number 1? 16(4) + 9(-7) = 64 – 63 = 1 16(4) + 9(-7) = 64 – 63 = 1 Yes, can create any number with 16 and 9 Yes, can create any number with 16 and 9 To create any number m: To create any number m: 16(4m) + 9(-7m) = m 16(4m) + 9(-7m) = m B zout showed back in 18th century B zout showed back in 18th century • If a and b are relatively prime, • If a and b are relatively prime, then there exists integers x and y such that ax+by=1 11 then there exists integers s and t such that as+bt=1 12 gcds as Linear Étienne Bézout gcds as Linear Étienne Bézout Combinations (1730‐1783) Combinations (1730‐1783) B zout’s Theorem: If a and b are positive integers, B zout’s Theorem: If a and b are positive integers, then there exist integers s and t such that then there exist integers s and t such that gcd(a,b) = sa + tb. gcd(a,b) = sa + tb. (proof in exercises of Section ) (proof in exercises of Section ) Idea: Idea: gcd(a,b) = g gcd(a,b) = g a/g and b/g are relatively prime a/g and b/g are relatively prime g is the largest that divides both of them g is the largest that divides both of them Thus, there exists s and t such that (a/g)s + (b/g)t = 1 Thus, there exists s and t such that (a/g)s + (b/g)t = 1 Definition: If a and b are positive integers, then Definition: If a and b are positive integers, then integers s and t such that gcd(a,b) = sa + tb are called integers s and t such that gcd(a,b) = sa + tb are called B zout coefficients of a and b. The equation gcd(a,b) = B zout coefficients of a and b. The equation gcd(a,b) = sa + tb is called B zout’s identity. 13 sa + tb is called B zout’s identity. 14 Euclidean Algorithm Euclidean Algorithm Euclid • The Euclidean algorithm expressed in (325 B.C.E. – 265 B.C.E.) pseudocode is: • The Euclidian algorithm is an efficient method for computing the greatest common divisor of two integers. It is based on the idea that gcd(a,b) is equal to gcd(a,c) when procedure gcd(a, b: positive integers) a b and c is the remainder when a is divided by b. x := a Example: Find gcd( , ): y := b • 287 91 ∙ 3 14 Divide 287 by 91 while y • 91 14 ∙ 6 7 Divide 91 by 14 r := x mod y • 14 7 ∙ 2 0 Divide 14 by 7 Stopping x := y condition y := r gcd( , ) = gcd( , ) = gcd( , ) = return x {gcd(a,b) is x} 15 16 Correctness of Euclidean Algorithm Correctness of Euclidean Algorithm Lemma : Let a = bq + r, where a, b, q, and r Lemma : Let a = bq + r, where a, b, q, and r are integers. Then gcd(a,b) = gcd(b,r). are integers. Then gcd(a,b) = gcd(b,r). Proof: Proof: – Suppose that d divides both a and b. – Suppose that d divides both a and b. Then d also divides a bq = r (by Theorem of Then d also divides a bq = r (by Theorem of Section ). Hence, any common divisor of a and b Section ). Hence, any common divisor of a and b must also be any common divisor of b and r. must also be any common divisor of b and r. – Suppose that d divides both b and r. – Suppose that d divides both b and r. Then d also divides bq + r = a. Hence, any common Then d also divides bq + r = a. Hence, any common divisor of a and b must also be a common divisor of divisor of a and b must also be a common divisor of b and r. b and r. – Therefore, gcd(a,b) = gcd(b,r). – Therefore, gcd(a,b) = gcd(b,r). 17 18 Correctness of Euclidean Algorithm Correctness of Euclidean Algorithm • Suppose that a and b are positive r0 = r1q1 + r2 0r2 < r1, • Suppose that a and b are positive r0 = r1q1 + r2 0r2 < r1, integers with a b. r = r q + r 0r < r , integers with a b. r = r q + r 0r < r , Let r = a and r = b. 1 2 2 3 3 2 Let r = a and r = b. 1 2 2 3 3 2 0 1 ∙ 0 1 ∙ Successive applications of the division Successive applications of the division algorithm yields: ∙ algorithm yields: ∙ ∙ ∙ rn‐2 = rn‐1qn‐1 + r2 0rn < rn‐1, rn‐2 = rn‐1qn‐1 + r2 0rn < rn‐1, rn‐1 = rnqn . rn‐1 = rnqn . • Eventually, a remainder of zero occurs in the sequence of terms: a = r0 > r1 • Eventually, a remainder of zero occurs in the sequence of terms: a = r0 > r1 > r2 ∙ ∙ ∙ 0. The sequence can’t contain more than a terms. > r2 ∙ ∙ ∙ 0. The sequence can’t contain more than a terms. • By Lemma 1 • By Lemma 1 gcd(a,b) = gcd(r0,r1) = ∙ ∙ ∙ gcdrn‐1,rn gcdrn , 0 rn. gcd(a,b) = gcd(r0,r1) = ∙ ∙ ∙ gcdrn‐1,rn gcdrn , 0 rn. • Hence the greatest common divisor is the last nonzero remainder in • Hence the greatest common divisor is the last nonzero remainder in the sequence of divisions. the sequence of divisions. 19 20 Finding gcds as Linear Combinations Finding gcds as Linear Combinations Example: Express gcd(252,198) = 18 as a linear combination Example: Express gcd(252,198) = 18 as a linear combination of 252 and 198. of 252 and 198. Solution: First use the Euclidean algorithm to show Solution: First use the Euclidean algorithm to show gcd(252,198) = 18 gcd(252,198) = 18 i. 252 1∙198 54 i. 252 1∙198 54 ii. 198 3 ∙54 36 ii. 198 3 ∙54 36 iii. 54 1 ∙36 18 iii. 54 1 ∙36 18 iv. 36 2 ∙18 iv. 36 2 ∙18 – Now working backwards, from iii and i above – Now working backwards, from iii and i above • 18 54 1 ∙36 • 18 54 1 ∙36 • 36 198 3 ∙54 • 36 198 3 ∙54 – Substituting the 2nd equation into the 1st yields: – Substituting the 2nd equation into the 1st yields: • 18 54 1 ∙198 3 ∙54 4 ∙54 1 ∙198 • 18 54 1 ∙198 3 ∙54 4 ∙54 1 ∙198 – Substituting 54 252 1 ∙198 from i yields: – Substituting 54 252 1 ∙198 from i yields: • 18 4 ∙252 1 ∙198 1 ∙198 4 ∙252 5 ∙198 • 18 4 ∙252 1 ∙198 1 ∙198 4 ∙252 5 ∙198 • This method illustrated above is a two pass method. It first uses • This method illustrated above is a two pass method.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us