This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Algorithms NonLecture M: NumberTheoretic Algorithms And its one, two, three, What are we fighting for? Dont tell me, I dont give a damn, Next stop is Vietnam; [or: This time well kill Saddam] And its five, six, seven, Open up the pearly gates, Well there aint no time to wonder why, Whoopee! Were all going to die. Country Joe and the Fish IFeelLikeImFixintoDie Rag" (1967) There are 0 kinds of mathematicians: Those who can count modulo 2 and those who cant. Anonymous God created the integers; all the rest is the work of man. Kronecker M Number Theoretic Algorithms M.1 Greatest Common Divisors Before we get to any actual algorithms, we need some definitions and preliminary results. Unless specifically indicated otherwise, all variables in this lecture are integers. The symbol ZZ (from the German word Zahlen", meaning numbers or to count) to denote the set of integers. We say that one integer d divides another integer n , or that d is a divisor of n , if the quotient n / d is also an integer. Symbolically, we can write this definition as follows: d  n n d = n d In particular, zero is not a divisor of any integer is not an integerbut every other integer is a divisor of zero. If d and n are positive, then d  n immediately implies that d n . Any integer n can be written in the form n = qd + r for some nonnegative integer 0 r  d 1  . Moreover, the choices for the quotient q and remainder r are unique: q = n d and r = n mod d = n d n d . Note that the remainder n mod d is always nonnegative, even if n < 0 or d < 0 or both. 1 If d divides two integers m and n , we say that d is a common divisor of m and n . Its trivial to prove (by definition crunching) that any common divisor of m and n also divides any integer linear combination of m and n : ( d  m ) and ( d  n ) = d  ( am + bn ) The greatest common divisor of m and n , written gcd ( m , n ) , 2 is the largest integer that divides both m and n . Sometimes this is also called the greater common denominator . The greatest common divisor has another useful characterization as the smallest element of another set. Lemma 1. gcd ( m , n ) is the smallest positive integer of the form am + bn . 1 The sign rules for the C / C ++ / Java % operator are just plain stupid. I cant count the number of times Ive had to write x = (x+n)%n; instead of x %= n; . Frickin idiots . Gah! 2 Do not use the notation ( m , n ) for greatest common divisor, unless you want Notation Kitty to visit you in the middle of the night and remove your eyes while you sleep. Nice kitty. 1 Algorithms NonLecture M: NumberTheoretic Algorithms Proof: Let s be the smallest positive integer of the form am + bn . Any common divisor of m and n is also a divisor of s = am + bn . In particular, gcd ( m , n ) is a divisor of s , which implies that gcd ( m , n ) s ....
View Full
Document
 Spring '09
 A

Click to edit the document details