1 / 9

Euclid's Algorithm and GCD Calculation

Learn about Euclid's Algorithm and how to calculate the greatest common divisor (GCD) of two numbers. Also explore the applications of GCD in number theory.

ashearer
Download Presentation

Euclid's Algorithm and GCD Calculation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DTTF/NB479: Dszquphsbqiz Day 9 • Announcements: • Homework 1 returned. Comments from Kevin? • Matlab: tutorial available at http://www.math.ufl.edu/help/matlab-tutorial/ • Homework 2 due Tuesday • Quiz this Friday on concepts from chapter 2 (tentative) • Practical quiz next week on breaking codes from chapter 2 • Questions? • Today: • Euclid’s algorithm • Congruences if time

  2. Basics 1: Divisibility Definition: Property 1: Property 2 (transitive): Property 3 (linear combinations):

  3. Basics 2: Primes • Any integer p > 1 divisible by only p and 1. • How many are there? • Prime number theorem: • Let p(x) be the number of primes less than x. • Then • Application: how many 319-digit primes are there? • Every positive integer is a unique product of primes.

  4. Basics: 3. GCD • gcd(a,b)=maxj (j|a and j|b). • Def.: a and b are relatively prime iff gcd(a,b)=1 • gcd(14,21) easy… • What about gcd(1856, 5862)? • gcd(500267500347832384769, 12092834543475893256574665)? • Do you really want to factor each one? • What’s our alternative?

  5. Euclid’s Algorithm gcd(a,b) { if (a < b) swap (a,b) // a > b r = a % b while (r ~= 0) { a = b b = r r = a % b } gcd = b // last r ~= 0 } Calculate gcd(1856, 5862) =2

  6. gcd(a,b) { if (a > b) swap (a,b) // a > b r = a % b while (r ~= 0) { a = b b = r r = a % b } gcd = b // last r ~= 0 } Euclid’s Algorithm Assume a > b Let qi and ri be the series of quotients and remainders, respectively, found along the way. a = q1b + r1 b = q2r1 + r2 r1 = q3r2 + r3 ... ri-2 = qiri-1 + ri rk-2 = qkrk-1 + rk rk-1 = qk+1rk rk is gcd(a,b) You’ll prove this computes the gcd in Homework 3 (by induction)…

  7. Fundamental result: If d = gcd(a,b) then ax + by = d • For some integers x and y. • These ints are just a by-product of the Euclidean algorithm! • Allows us to find a-1 (mod n) very quickly… • Choose b = n and d = 1. • If gcd(a,n) =1, then ax + ny = 1 • ax = 1 (mod n) because it differs from 1 by a multiple of n • Therefore, x = a-1 (mod n). • Why does this work? • How do we find x and y?

  8. Why does this work? Assume a > b Let qi and ri be the series of quotients and remainders, respectively, found along the way. a = q1b + r1 b = q2r1 + r2 r1 = q3r2 + r3 ... ri-2 = qiri-1 + ri rk-2 = qkrk-1 + rk rk-1 = qk+1rk Given a,b ints, not both 0, and gcd(a,b) = d. Prove ax + by = d Recall gcd(a,b,)=d = rkis the last non-zero remainder found via Euclid. We’ll show the property true for all remainders rj (by strong induction)

  9. How to find x and y? x and y swapped from book, which assumes that a < b on p. 69 Assume a > b Let qi and ri be the series of quotients and remainders, respectively, found along the way. a = q1b + r1 b = q2r1 + r2 r1 = q3r2 + r3 ... ri-2 = qiri-1 + ri rk-2 = qkrk-1 + rk rk-1 = qk+1rk To find x, take x0 = 1, x1 = 0, xj = xj-2 – qj-1xj-1 To find y, take y0 = 0, y1 = 1, yj = yj-2 – qj-1yj-1 Use to calculate xk and yk (the desired result) Example: gcd(5862,1856)=2 Yields x = -101, y = 319 Check: 5862(-101) + 1856(319) = 2?

More Related