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 the gcd of some pair, then the smaller number in the pair must be greater than or equal to the kth Fibonacci number.
    • , order of growth is
      • n is the smaller of the two inputs to the procedure
      • k is the number of steps taken by the process

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

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
  1. gcd(0, v) = v, because everything divides zero, and v is the largest number that divides v. Similarly, gcd(u, 0) = u.
  2. gcd(2u2v) = 2 · gcd(uv)
  3. gcd(2uv) = gcd(uv), if v is odd (2 is not a common divisor). Similarly, gcd(u2v) = gcd(uv) if u is odd.
  4. gcd(uv) = gcd(|u − v|, min(uv)), if u and v are both odd.