cse101_9_28_11 - show something simpler Lemma If a>= b...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Modular Arithmetic 1. Greatest common divisor A. The GCD of a,b is the largest integer that divides both of them, eg. GCD (10,25) = 5. GCD(1650, 363) = ? Factoring is exponential B. We’d like an algorithm for computing the GCD of a,b. Idea: function gcd(a,b) Input: Integers a >= b >= 0. For c = b down to 1. If c| a and c | b: output c and halt. Running time if a,b are n-bit integers. O(n 2 2 n ). Inner loop: O(n 2 ) division, but could loop O(2 n ) times. C. Evelid’s algorithm: function Evelid(a,b) Input Integers a >= b >= 0. Output: gcd (a,b). if b = 0: return a. return Evelid (b, a mod b). D. Why does it work? Evelid’s rule: if a >=b then gcd (a,b) = gcd (a mod b, b) actually can
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: show something simpler. Lemma: If a >= b then gd (a,b) = gcd(a - b, b). Proof: Any number that divides a and b also divides a – b mod b. any number that divides a-b mod b also divides a and b. therefore, (a,b) and (a-b,b) have the same divisors, therefore, same GCD. Gcd (550, 121) = gcd (550 mod 121, 121) = gcd (121, 66) = gcd (55, 11) = gcd (11, 0) Gcd(231, 60) = gcd(51, 9) = gcd(9, 6) = gcd(6,3) = 3. E. How fast is it: Lemma: if a >=b then a mod b < a/2. Case(i) b <= a/2 case 2: b > a/2. . F....
View Full Document

This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.

Ask a homework question - tutors are online