Abstract
- Stands for Greatest Common Divisor, also known as Greatest Common Factor(GCF)
- The largest positive Integer (整数) that is a Factor for both two or more integers
- Basically a product of all the common Prime Number (质数) factor in the given set of integers
One of given integer is 0
The GCD of
0
and another number is , since0
divided by any number results in a remainder of0
GCD is 1
This means there isn’t a single common Prime Number (质数) Factor between the two numbers
Euclidean Algorithm
- The efficient way of finding GCD
- The Euclidean Algorithm states that
- Given 2 Integer (整数) - & , where . With the use of Divisibility Mathematical Model , when is , is the GCD
- The
gcd()
function implemented with Recursion, Worst Time Complexity isO(logn)
Proof
Not a very clear proof, just for better understanding
- Euclidean Algorithm Proof Reference
- Let
d
be the GCD ofa
andb
→d|a
andd|b
- And we know
a = bq + r
, sor = a - bq
- With
r = a - bq
, we are sure we can factor out ad
froma - bq
, sinced|a
andd|bq
, sinceq
is an Integer (整数) - So since
d|r
, andd|b
, we can reduce the range by findinggcd(b, r)
Brute-force Method: List Factors
Write out the Prime Number (质数) of each given Integer (整数) and identify the prime numbers that appears in both. The GCD is the product of the common set of prime numbers