Lecture 10

Coprimality

Now we’re going to introduce some very useful concepts. Rather than (as we were doing before) looking at one number at a time, it’s going to turn out to be really useful to consider two numbers and compare their factors.


Definition: Let aa and bb be integers. A common divisor of aa and bb is an integer dd such that dad\mid a and dbd\mid b. The greatest common divisor of aa and bb, written gcd(a,b)\gcd(a,b) (or sometimes as hcf(a,b)\operatorname{hcf}(a,b) or sometimes even just (a,b)(a,b) for short) is the largest common divisor of aa and bb.

That definition probably just says that a greatest common divisor is what you’d expect it to be, given the name!

That definition is dangerous, because it does something I’ve warned you against doing several times: it defines something that looks like a function, but it doesn’t prove that it is a function.

There are two reasons why the gcd might not exist; we need to satisfy ourselves that neither is a problem:

As happens quite often, the remark above, which looks like a slightly pedantic point at first, really says something practically important. Indeed, it gives us a way of finding the greatest common divisor of two numbers: to find gcd(a,b)\gcd(a,b) we could just count down from a|a| and stop when we reach the first common divisor.

For example, gcd(9,15)=3\gcd(9,15) = {}3 and gcd(30,42)=6.\gcd(-30,42) = {}6.

This approach to finding greatest common divisors is pretty terrible: imagine being asked to find gcd(123456789,987654321)\gcd(123456789,987654321) by this approach!

Another way might be to work out all factors of one of the numbers (aa, for example) and work out which of them are factors of bb. 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 123456789123456789 still.

We will see a much better way soon, but, first, let’s spot some easy properties of greatest common divisors.

For all integers aa and bb, we have gcd(a,b)=gcd(b,a),\gcd(a,b) = \gcd(b,a), because the definition is symmetric in aa and bb.

Also, for all positive integers aa, we have gcd(a,a)=a,\gcd(a,a) = a, and gcd(a,1)=1,\gcd(a,1) = 1, and gcd(a,b)=gcd(a,b).\gcd(a,b) = \gcd(a,-b).

A slightly less obvious property is:

Proposition

Let a,ba,b and kk be integers. Then gcd(a,b)=gcd(a+kb,b).\gcd(a,b) = \gcd(a+kb,b).

Proof

We’ll show that the common divisors of aa and bb are the same as the common divisors of a+kba+kb and bb.

Suppose first that dd is a common divisor of aa and bb; in other words, dad\mid a and dbd\mid b. Then we can write a=mda=md and b=ndb=nd for some integers mm and nn. But then a+kb=md+knd=(m+kn)d,a+kb=md+knd=(m+kn)d, so da+kbd\mid a+kb, so dd is a common divisor of a+kba+kb and bb.

Similarly, if dd is a common divisor of a+kba+kb and bb, then we can write a+kb=lda+kb = ld and b=ndb=nd. But then a=a+kbkb=ldknd=(lkn)d,a = a+kb-kb = ld-knd = (l-kn)d, so dad\mid a, so dd is a common divisor of aa and bb.

Since we’ve now proved that aa and bb have the same common divisors as a+kba+kb and bb, 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 aa and bb, the least common multiple lcm(a,b)\operatorname{lcm}(a,b) is the smallest positive integer which is a multiple both of aa and bb.

Given that abab is a common multiple of aa and bb, the least common multiple always exists (and is at most abab: we could find it by counting up from 11 to abab, stopping on the first common multiple).

The last piece of terminology we might want is this:
Definition: Two integers aa and bb are said to be coprime, or relatively prime, if gcd(a,b)=1\gcd(a,b)=1.

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:

Proposition

[Division with Remainder] Let aa and bb be integers, with b>0b>0. One can write a=qb+ra = qb+r for integers qq (the quotient) and rr (the remainder) such that 0r<b0\leq r<b.

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 b>0b>0. It’s true for b<0b<0, too, we just have to say that the remainder rr satisfies 0r<b0\leq r<-b 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 gcd(126,70)\gcd(126,70). If we divide 126126 by 7070 we get 11 with remainder 5656; in other words 126=1×70+56126 = 1\times 70+56. That means that

gcd(126,70)=gcd(56+1×70,70)=gcd(56,70)=gcd(70,56).\begin{aligned} \gcd(126,70) &= \gcd(56+1\times 70,70)\\ &= \gcd(56,70)\\ &= \gcd(70,56).\end{aligned}

That made the problem much smaller, and we can do the same trick repeatedly: gcd(70,56)=gcd(14+1×56,56)=gcd(14,56)=gcd(56,14).\begin{aligned} \gcd(70,56) &= \gcd(14+1\times 56,56)\\ &= \gcd(14,56)\\ &= \gcd(56,14).\end{aligned} That’s smaller still. Let’s see what happens next: gcd(56,14)=gcd(0+14×4,14)=gcd(0,14)=14.\begin{aligned} \gcd(56,14) &= \gcd(0+14\times 4,14)\\ &= \gcd(0,14)\\ &= 14.\end{aligned} As 5656 is a multiple of 1414, of course we get remainder 00, so we stop here: the greatest common divisor is 1414.

For another example, let’s suppose we want the greatest common divisor of 556556 and 296296. We write gcd(556,296)=gcd(1×296+260,296)=gcd(260,296)=gcd(296,260)=gcd(1×260+36,260)=gcd(36,260)=gcd(260,36)=gcd(7×36+8,36)=gcd(8,36)=gcd(36,8)=gcd(4×8+4,8)=gcd(4,8)=gcd(8,4)=gcd(2×4+0,4)=gcd(0,4)=4.\begin{aligned} &{}\gcd(556,296)\\ &{}=\gcd(1\times296+260,296) {}=\gcd(260,296) {}=\gcd(296,260)\\ &{}=\gcd(1\times 260+36,260) {}=\gcd(36,260) {}=\gcd(260,36)\\ &{}=\gcd(7\times 36+8,36) {}=\gcd(8,36) {}=\gcd(36,8)\\ &{}=\gcd(4\times 8+4,8) {}=\gcd(4,8) {}=\gcd(8,4)\\ &{}=\gcd(2\times 4+0,4) {}=\gcd(0,4) {}= 4.\end{aligned}