Divisor
A divisor of n, also called a factor of n, is an integer m that can be multiplied by some integer to produce n.
and n is a multiple of m.
then
GCD
Greatest common divisor. It is also termed as the highest common factor (HCF) or the greatest common factor (GCF).
Euclidean algorithm - Wikipedia
Properties
- Bezout’s Identity
- If and then
- Lamé’s Theorem:
- If Euclid’s Algorithm requires
k
steps to compute thegcd
of some pair, then the smaller number in the pair must be greater than or equal to thekth
Fibonacci number. - , order of growth is
n
is the smaller of the two inputs to the procedurek
is the number of steps taken by the process
- If Euclid’s Algorithm requires
Method 1: Prime Factorizations
to compute , we find the prime factorizations and ; the GCD is then
I Do Maths · Prime Numbers and Prime Factorization
Method 2: Euclidean Algorithm
The Euclidean Algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number.
Code for GCD
- gcd(0, v) = v, because everything divides zero, and v is the largest number that divides v. Similarly, gcd(u, 0) = u.
- gcd(2u, 2v) = 2 · gcd(u, v)
- gcd(2u, v) = gcd(u, v), if v is odd (2 is not a common divisor). Similarly, gcd(u, 2v) = gcd(u, v) if u is odd.
- gcd(u, v) = gcd(|u − v|, min(u, v)), if u and v are both odd.