The Euclidean Algorithm computes greatest common divisors quickly, but also, with only slightly more work, yields a very useful fact: can be expressed as a linear combination of and That is, there exist integers and such that For example,
The Extended Euclidean Algorithm will tell us how to find and Rather than give a set of equations, we’ll show how it works with the two examples we calculated in Subsection 3.1.3.
When we computed we did the following calculation:
For the Extended Euclidean Algorithm, we’ll form a table with three columns and explain how they arise as we compute them.
We begin by forming two rows and three columns. The first entries in the rows are the original numbers we started with, namely 12345 and 11111. We will do some calculations so that we always have
where and are integers. The first two lines are trivial: and
12345 | 1 | 0 |
11111 | 0 | 1 |
The first line in our calculation tells us that We rewrite this as Using this, we compute
yielding the following:
12345 | 1 | 0 | |
11111 | 0 | 1 | |
1234 | 1 | 1 | (1st row) (2nd row). |
In effect, we have done the following subtraction:
Therefore, the last line tells us that
We now move to the second row of our gcd calculation. This says that which we rewrite as This tells us to compute (2nd row) (3rd row). We write this as
12345 | 1 | 0 | |
11111 | 0 | 1 | |
1234 | 1 | 1 | |
5 | 9 | 10 | (2nd row) (3rd row). |
The last line tells us that
The third row of our gcd calculation tells us that This becomes
12345 | 1 | 0 | |
11111 | 0 | 1 | |
1234 | 1 | 1 | |
5 | 9 | 10 | |
4 | 2215 | 2461 | (3rd row) (4th row). |
Finally, we obtain
12345 | 1 | 0 | |
11111 | 0 | 1 | |
1234 | 1 | 1 | |
5 | 9 | 10 | |
4 | 2215 | 2461 | |
1 | 2224 | 2471 | (4th row) (5th row). |
This tells us that
Notice that as we proceeded, we were doing the Euclidean Algorithm in the first column. The first entry of each row is a remainder from the gcd calculation, and the entries in the second and third columns allow us to express the number in the first column as a linear combination of 12345 and 11111. The quotients in the Euclidean Algorithm tell us what to multiply a row by before subtracting it from the previous row.
Let’s do another example using 482 and 1180 and our previous calculation that
1180 | 1 | 0 | |
482 | 0 | 1 | |
216 | 1 | 2 | (1st row) (2nd row) |
50 | 5 | (2nd row) (3rd row) | |
16 | 9 | (3rd row) (4th row) | |
2 | 71 | (4rd row) (5th row). |
The end result is
To summarize, we state the following.
Let and be integers with at least one of nonzero. There exist integers and which can be found by the Extended Euclidean Algorithm, such that
As a corollary, we deduce the lemma we needed during the proof of the uniqueness of factorization into primes.
If is a prime and divides a product of integers then either or More generally, if a prime divides a product then must divide one of the factors
Proof. First, let’s work with the case If divides we are done. Now assume We claim Since is prime, or Since the gcd cannot be Therefore, so there exist integers with Multiply by to obtain Since and we have so as claimed.
If then or If we’re done. Otherwise, We now have a shorter product. Either in which case we’re done, or divides the product of the remaining factors. Continuing in this way, we eventually find that divides one of the factors of the product.
The property of primes stated in the corollary holds only for primes. For example, if we know a product is divisible by 6, we cannot conclude that or is a multiple of 6. The problem is that and the 2 could be in while the 3 could be in as seen in the example More generally, if is any composite, then but and Therefore, the primes, and 1, are the only integers with the property of the corollary.