Fish Touching🐟🎣

GCD

Jul 17, 2023

# 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.
$n = km$ then $m | n$

# GCD

Greatest common divisor. It is also termed as the highest common factor (HCF) or the greatest common factor (GCF).
Euclidean algorithm - Wikipedia

# Properties

# Method 1: Prime Factorizations

to compute $gcd(48, 180)$, we find the prime factorizations $48 = 2^4 \cdot 3^1$ and $180 = 2^2 \cdot 3^2 \cdot 5^1$; the GCD is then $2^{min(4,2)} · 3^{min(1,2)} · 5^{min(0,1)} = 2^2 · 3^1 · 5^0 = 12$
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.