Learn/Number Theory/Euclidean Algorithm
Number Theory • Topic 10

Euclidean Algorithm

The Euclidean Algorithm is an efficient method for computing the greatest common divisor (GCD) of two numbers. It is much faster than prime factorization.

The Algorithm

To find where :

  1. Divide by to get remainder : .
  2. Replace with .
  3. Repeat until the remainder is 0.
  4. The last non-zero remainder is the GCD.
Lemma

Example (GCD(252, 105))
Result: .

Geometric Interpretation

The algorithm is equivalent to tiling a rectangle of size with the largest possible squares.
  1. Fill with squares.
  2. Remaining strip is .
  3. Fill with squares...
  4. The side length of the smallest square is the GCD.

Complexity

Lamé's Theorem states that the number of steps is at most 5 times the number of digits in the smaller number (related to Fibonacci numbers).

Practice Problems

Exercise (Problem 1)
Use the Euclidean Algorithm to find .
Exercise (Problem 2)
Find .
Exercise (Problem 3)
If is the -th Fibonacci number, prove that the Euclidean algorithm takes exactly steps to compute .