





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Lecture notes from cs3510 a, fall 2005, covering euclid's algorithm for finding the greatest common divisor (gcd) of two integers and the concept of modular division. The notes include the idea behind euclid's algorithm, its implementation, and the running time analysis. Additionally, an extension to euclid's algorithm for checking if a number is the gcd is discussed, as well as the concept of modular division and its inverse.
Typology: Study notes
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































CS3510 A, Fall 2005 – p. 1/
CS3510 A, Fall 2005 – p. 2/
No polynomial procedure is known for factoring integers.Different method must be used.
CS3510 A, Fall 2005 – p. 2/
mod^ b, b)^ CS3510 A, Fall 2005 – p. 3/
mod^ b, b) function^ EUCLID(a, b) Input: two positive integers
a, b^ with^ a^ ≥^ b Output: gcd(a, b) if^ b^ = 0^ then return^ a return^ EUCLID(b, a^ mod^ b) Running time?
CS3510 A, Fall 2005 – p. 3/
mod^ b, b) function^ EUCLID(a, b) Input: two positive integers
a, b^ with^ a^ ≥^ b Output: gcd(a, b) if^ b^ = 0^ then return^ a return^ EUCLID(b, a^ mod^ b) Running time? Claim^ If^ a^ ≥^ b^ then^ a^ mod
a b ≤. 2 Number of recursive calls:
2 ⌈logb⌉.^2 Since^ n^ =^ ⌈loga⌉^ +^ ⌈logb^2
⌉, we have^ O(n)^ rounds and the (^2 3) total time is O(n · n=^ n)^ (^2) (nfor division.)^ CS3510 A, Fall 2005 – p. 3/
CS3510 A, Fall 2005 – p. 4/
) =^ d^ =^ ax^ +^ by.^ CS3510 A, Fall 2005 – p. 4/
) =^ d^ =^ ax^ +^ by. function^ EXTENDED-EUCLID(a, b
Input: two positive integers
a, b^ with^ a^ ≥^ b Output: integers^ x, y, d^ such that
d^ =^ gcd(a, b) =^ ax^ +^ by if^ b^ = 0^ then return^ (1,^0 , a) ′′(x, y, d) =EXTENDED-EUCLID
(b, a^ mod^ b) a′′ ′ return (y, x− ⌊⌋y, d)^ b^
CS3510 A, Fall 2005 – p. 4/
a^ if ax^ ≡^ 1(^ mod^ m). −^1 We denote^ x^ :=^ a( at most one such
x^ modulo^ m^ exists (why?)).
CS3510 A, Fall 2005 – p. 5/
a^ if ax^ ≡^ 1(^ mod^ m). −^1 We denote^ x^ :=^ a( at most one such
x^ modulo^ m^ exists (why?)). Proposition^ For any^ a < m, a
has a multiplicative inverse modulo^ m^ if and only if it is relatively prime to
m.^ When this inverse exists then it can be found in time
(^3) O(logm). Use Extended-Euclid’s algorithm to find the inverse of a if
a and^ m^ are relatively prime.
CS3510 A, Fall 2005 – p. 5/