Numerical Example

We have seen in the theorem, we can represent the greatest common divisor of two integers as a linear combination of them, and it is actually the smallest positive linear combination. The question is, how can we find such a linear combination, and how can we find the greatest common divisor efficiently?

We can take two numbers and as an example. One naive idea is use subtraction repeatedly to find make the number smaller but remains positive. The following table shows the process:

Step
1324148176
217614828
314828120
41202892
5922864
6642836
736288
828820
920812
101284
11844
12440

As the process terminates, we find the greatest common divisor of and is , and we took steps to find it. This methodology will always work, but it is not very efficient.

The Euclidean Algorithm is an improved version of the above process, it reduces the number of steps needed to find the greatest common divisor, with the price of doing division instead of subtraction. The following table shows the process of the Euclidean Algorithm:

Step
1324148324 = 148 * 2 + 2828
214828148 = 28 * 5 + 88
328828 = 8 * 3 + 44
4848 = 4 * 2 + 00

With the Euclidean Algorithm, we only need steps to find the greatest common divisor of and . The process is replacing the dividend with the divisor, and the divisor with the remainder, and repeat the process until the remainder becomes . The greatest common divisor is the last non-zero remainder.

Euclidean Algorithm

The Euclidean Algorithm can be formally stated as follows:

Theorem

Let and be two integers, with and both positive. Then the greatest common divisor of and can be found by the following process:

The greatest common divisor of and is .

Proof of Correctness

The idea this time is to show the greatest common divisor of the pairs of numbers remain the same throughout the process. The process in the Euclidean Algorithm is recursive, so it is sufficient to show the invariance of the greatest common divisor for one step. We state it as a lemma:

Lemma

Let be positive integers, and let such that , and . Then the greatest common divisor of and is the same as the greatest common divisor of and .

Proof of Lemma

We will show the pair and share the same exact set of divisors. We will show two directions:

  1. If and , then .
  2. If and , then .

The first direction is easy, if and , then by this property.

For the second direction is less obvious, if and , then we can write and . Then we have:

This implies .

Therefore, the greatest common divisor of and is the same as the greatest common divisor of and .

Warning

Make sure you know how to prove this property.

Warning

GCD is not in general stable under linear combinations, find examples such that:

Can you figure out a condition on such that the equality holds?

Proof of Theorem

This completes the proof of the Euclidean Algorithm.

Backtracking to Find the Linear Combination

As we mentioned in the lecture, the Euclidean Algorithm not only returns the greatest common divisor, but also the linear combination of the two numbers. We can backtracking the table to find the linear combination:

You could also backtraking the first table to find the linear combination.