Interactive · 2 questions
Suppose that you have two distinct positive integers and with , and you would like to find their greatest common factor; that is, the largest positive integer such that and .
You could solve this problem in a relatively straightforward manner by computing the prime factorization of each number, and by taking the minimum exponent of each prime number.
However, this system is problematic.
Why might this be?
Finding prime factorizations of large numbers can be difficult and time-consuming, due to the large amount of trial and error.
For example, supposed you wanted to write a "greatest common factor" algorithm on your computer using some programming language. The problem with using factorization is that the code becomes a lot longer, fixing errors becomes a lot more difficult, and the program becomes slower (although this is hard to notice because computers are amazingly fast).
We would like to search for a method for finding the greatest common factor that has less trial and error and is faster.
The expression is quite unwieldy due to the large numbers. Is there a way we can relate this quantity to some smaller numbers? Take a moment to think about this before moving ahead.
The answer comes from an extremely simple divisibility rule, one that is so obvious that we hardly stop to think about it:
If and , then and .
Thus, if is the greatest common factor of and , then and , which means that !
So we know that divides both and . Notice that and . Thus, we are clearly well on our way to achieving smaller numbers.
But we have only shown that ! We have not shown equality!
Fortunately, this is also fairly easy to prove, due to another powerful divisibility rule:
If divides either or but not both, then does not divide .
From this, it easily follows that . Thus, we have .
But will typically still be a fairly large number!
What to do...
We can continue decreasing the numbers as many times as we want, until we hit a limit.
This will occur when we finally get two of the same number, and repeating the process gives us . In this case, the number immediately before is the greatest common factor.
Alternatively, you can always repeat the process until you feel comfortable enough with the remaining numbers.
In addition, if one number is much larger than another, one may have to subtract a lot of times. Think about how this process may be expedited before moving forward.
We can replace the repeated subtractions with a division, followed by taking the remainder!
With all of this in mind, we can make a precise algorithmic process describing the Euclidean algorithm:
-
Label the larger number and the smaller number .
-
Divide by and let the remainder be .
-
Replace with , and replace with .
-
Repeat steps 2-3 until .
-
The final number is the greatest common factor of the two original numbers.