Another way might be to work out all factors of one of the numbers (, for example) and work out which of them are factors of . That’s also a pretty terrible way, because factorising numbers is hard work: it seems like a lot of work to find all factors of still.
We will see a much better way soon, but, first, let’s spot some easy properties of greatest common divisors.
For all integers and , we have because the definition is symmetric in and .
Also, for all positive integers , we have and and
A slightly less obvious property is:
Let and be integers. Then
We’ll show that the common divisors of and are the same as the common divisors of and .
Suppose first that is a common divisor of and ; in other words, and . Then we can write and for some integers and . But then so , so is a common divisor of and .
Similarly, if is a common divisor of and , then we can write and . But then so , so is a common divisor of and .
Since we’ve now proved that and have the same common divisors as and , it follows that they have the same greatest common divisor.
We should also mention that the greatest common divisor has a close cousin:
Definition: Given two positive integers and , the least common multiple is the smallest positive integer which is a multiple both of and .
Given that is a common multiple of and , the least common multiple always exists (and is at most : we could find it by counting up from to , stopping on the first common multiple).
The last piece of terminology we might want is this:
Definition: Two integers and are said to be coprime, or relatively prime, if .
Division with Remainder
The above Proposition looks slightly dry at first: so what if you can add multiples of one number to another number without changing their greatest common divisor?
It turns out this is the key step in a surprisingly efficient method for calculating greatest common divisors. We can use it to make the numbers smaller; the question is, how? It turns out that this is something familiar to you all:
[Division with Remainder] Let and be integers, with . One can write for integers (the quotient) and (the remainder) such that .
It is not too hard to prove this: one can do it with two inductions, for example, (one for the negative and one for the positive integers), but I won’t do so here.
It’s reasonable to ask why we had to take . It’s true for , too, we just have to say that the remainder satisfies instead.
This observation gives us a really efficient way of computing greatest common divisors. Let’s illustrate it by an example.
Suppose we’re trying to compute . If we divide by we get with remainder ; in other words . That means that
That made the problem much smaller, and we can do the same trick repeatedly: That’s smaller still. Let’s see what happens next: As is a multiple of , of course we get remainder , so we stop here: the greatest common divisor is .
For another example, let’s suppose we want the greatest common divisor of and . We write
Here’s the general case:
[Euclid’s algorithm] Suppose we must calculate the greatest common divisor of two positive integers. Call them and with . If they’re not in the right order, we can swap them over earlier.
By division with remainder, we can write for some integers and with .
But then we have and since and we’ve made our numbers smaller.
If we keep doing this repeatedly, we’ll end up making one of the numbers zero and can stop (since ).
One might reasonably wonder just how fast Euclid’s algorithm really is. One good answer (not very hard to prove) is that if you’re trying to work out and , then the number of steps you need is always less than five times the number of digits of .
So working out will take less than divisions (actually, this one takes a lot less than , if you try it). Compared with the other methods we discussed, this makes it seem really good.
Euclid’s algorithm is in fact even more useful than it looks: using Euclid’s algorithm, if we have , that enables us to write in the form for some integers and . (We say that we’re writing it as a linear combination of and ). This will be really useful later: I promise!
Let’s see how this works with an example. We saw earlier that , so we expect to be able to find integers and such that .
Along the way we found that: Working through that backwards, we get that
Similarly, when we calculated that , we found that: This means that