Lecture 3: GCD and LCM

Recap and Summary

Last class period we talked about a handful of primality topics. These were the first steps in showing that prime numbers are the building blocks of the multiplicative structure of the integers. We saw how one can find all the primes less than or equal to some number N simply by knowing all the prime numbers less than or equal to $\root\of{N}$. We also asked and answered a handful of questions about primes, primarily concerning their distribution and methods for finding them. A few final topics about prime numbers

Goldbach's Conjecture

It was noted several hundred years ago that even numbers always seemed to be the sum of prime numbers. This is captured in the famous

Goldbach's Conjecture: Every even integer greater than 2 can be expressed as the sum of 2 prime numbers

Though this has been verified for lots and lots of even numbers, we still don't have a proof today.

Generating Prime Numbers

As a final word, I wanted to mention that there are other prime generating functions out there aside from the ones we talked about in class. For instance, it can be shown that there exists a real number x with the property that

(1)
\begin{align} \left\lfloor x^{3^n}\right\rfloor \end{align}

is always prime. One can also find primes recursively: the recursion $a_n = a_{n-1} + gcd(n,a_{n-1})$ with starting value $a_1 = 7$ gives either 1 or a prime number when you computer $a_n - a_{n-1}$ (thanks Chip and JohnMark!). With these prime generating functions out there, why aren't any of them being used to find new large primes?

What We'll Cover Today

Today we're switching gears and talking about divisors again, but this time we'll put a new spin on things by looking for common divisors of pairs of integers. This will lead us to the concept of greatest common divisor, a concept we'll explore in detail. We'll also talk about its cousin, the least common multiple of two integers. We'll finish the class by introducing a quick technique for computing the gcd of two integers known as the Euclidean Algorithm.

Greatest Common Divisor

For two integers a and b, it is often useful to know if there are any numbers d so that $d \mid a$ and $d \mid b$. For obvious reasons, such a number is called a common divisor. Certainly common divisors exist for any pair of integers a and b, since we know that 1 always divides any integer. We also know that common divisors can't get too big since divisors can't be any larger than the number they are dividing; hence a common divisor d of a and b must have $d \leq a$ and $d \leq b$, so that $d \leq \min\{a,b\}$. With all this as motivation, we have the following

Definition: The greatest common divisor of two integers a and b, written $(a,b)$, is the largest integer d so that $d \mid a$ and $d \mid b$. More generally, if you have a collection of integers $a_1, \cdots, a_r$, then the greatest common divisor of the collection $a_1,\cdots,a_r$, written $(a_1,\cdots,a_r)$, is the largest integer d so that $d \mid a_i$ for every i.

Example: Non-trivial GCD

Suppose we'd like to know the greatest common divisor of 12 and 15. We can see that

• the divisors of 12 are $\{\pm 1, \pm 2, \pm 3, \pm 4, \pm 6, \pm 12\}$
• the divisors of 15 are $\{\pm 1, \pm 3, \pm 5, \pm 15\}$

The largest number which is a member of both of these sets — and hence the greatest common divisor of 12 and 9 — is therefore 3. So we have shown (12,9) = 3.$\square$

Example: Trivial GCD

If we want to know the greatest common divisor of 21 and 10, then we write down their divisors:

• the divisors of 21 are $\{\pm 1, \pm 3, \pm 7, \pm 21\}$
• the divisors of 10 are $\{\pm 1, \pm 2, \pm 5, \pm 10\}$.

Hence we know that (21, 10) = 1.$\square$

Example: GCD of a collection

Looking at the lists of divisors we've already written out, we can see that the greatest common divisor of 12, 15 and 10 is 1, so that (12, 15, 10) = 1.$\square$

Example: GCDs with 0

We finish by noting that $(0,n) = |n|$ for any $n \in \mathbb{Z}$. This follows since 0 has the property that every integer divides it. Since $|n|$ is the largest divisor of n, this means that $(0,n) = |n|$.$\square$

Of particular interest in number theory are integers which do not share a common divisor, and because of their importance they get their own special name.

Definition: Two integers a and b are said to be relatively prime if $(a,b)$ = 1; i.e., if a and b share no common non-trivial divisors. A collection $a_1, \cdots, a_r$ is relatively prime if $(a_1,\cdots, a_r) = 1$. A collection $a_1,\cdots,a_r$ is said to be pairwise relatively prime if $(a_i,a_j)=1$ whenever $i \neq j$.

In the examples above, we see that 21 and 10 are relatively prime, and that the collection $\{10, 12, 15\}$ is relatively prime. Notice in this last example that the collection is relatively prime even though each pair of integers from the collection is not relatively prime. (As a general rule of thumb, you'll care more about whether a collection is pairwise relatively prime than whether it's relatively prime).

Properties of the GCD

Having met and played around with greatest common divisors a bit, we'll now introduce a few properties that they enjoy.

Removing the GCD

First, we'll see what we get when we remove the gcd of two integers.

Lemma: For any pair of integers a and b, we have $\displaystyle \left(\frac{a}{(a,b)},\frac{b}{(a,b)}\right) = 1$.

Proof: Since $(a,b) \mid a$ and $(a,b) \mid b$, there exist integers $q_a,q_b$ so that

(2)
\begin{align} a = (a,b)q_a \quad \mbox{ and } \quad b = (a,b)q_b. \end{align}

Our goal, then, is to show that $(q_a,q_b) = 1$. For this, suppose that there were some common divisor $d>1$ of both $q_a$ and $q_b$. This would imply that there exist integers $c_a,c_b$ satisfying

(3)
\begin{align} q_a = dc_a \quad \mbox{ and } q_b = dc_b. \end{align}

Putting this together with the previous equation, we'd then have

(4)
\begin{align} a = (a,b)q_a = (a,b) d c_a \quad \mbox{ and } \quad b = (a,b)q_b = (a,b)d c_b. \end{align}

Hence the integer $(a,b)d$ would be a common divisor of a and b which is larger than (a,b). This is a contradiction to the definition of greatest common divisor, and hence we are left to conclude that

(5)
\begin{align} \left(\frac{a}{(a,b)},\frac{b}{(a,b)}\right) = 1. \end{align}

$\square$

To see this result in action, recall that (12, 15) = 3. The lemma tells us that (12/3, 15/3) = (4,5) = 1 (a result which, I suppose, wouldn't be too hard to check without this result). $\square$

GCD as a linear combonation

Another surprisingly useful result to have around is the following Proposition, which says that the gcd of two integers a and b can be expressed as a linear combination of the a and b.

Proposition: For any two integers a and b, we have $\displaystyle (a,b) = \min\{ma+nb > 0: m,n \in \mathbb{Z}\}.$

Proof: To prove this result, we'll define $d = \min\{ma+nb > 0: m,n \in \mathbb{Z}\}$, and we'll show that it is in fact the greatest common divisor. Toward this end, we'll start by showing that d is a common divisor of both a and b, then we'll show that all other common divisors divide d (and so all other divisors are no bigger than d).

To show that d is a divisor of a, we'll start by using the Division Algorithm to find integers q and r with $0 \leq r < d$ that satisfy $a = qd + r$. Using the fact that $d = ma + nb$ for appropriately chosen integers m and n, this means we have

(6)
\begin{equation} r = a - qd = a-q(ma+nb) = (1-qm)a+(-qn)b. \end{equation}

But since d is chosen as the minimum positive integral linear combination of a and b, we therefore have $r = 0$, and so $a = qd$. Hence $d \mid a$, and a similar proof shows that $q \mid b$. So d is a common divisor.

Now we show that any other common divisor k of a and b is also a divisor of d, from which we conclude that $|k| \leq d$; this ensures that d is the greatest common divisor, as claimed. To show that $k \mid d$, we note that since $k \mid a$ and $k \mid b$, then we have k divides any integral linear combination of a and b. In particular, we have

(7)
\begin{align} k \mid ma+nb = d. \end{align}

$\square$

Corollary: Two integers a and b are relatively prime if and only if 1 can be written as an integral linear combination of a and b.

Example: Computing (a,a+2)

As a consequence of our result on integral linear combinations, we can show that for any integer a we have

(8)
\begin{align} (a,a+2) \in \{1,2\}. \end{align}

To see that this is true, notice that 2 can be written as $2 = (1)(a+2) + (-1)(a)$. Hence the minimal positive integral linear combination of a and a+2 is at most 2, and so is either 1 or 2. Can you determine a criterion which will determine whether (a,a+2) = 1 or (a,a+2) = 2?

Not Just the Largest Divisor…

Another interesting property which the gcd of two integers has is that all other common divisors of a and b will divide (a,b). For theoretical purposes, this is frequently a nifty property to use.

Lemma: For any pair of integers a and b, a common divisor d has $d \mid (a,b)$.

Proof: We proved this result in the midst of the previous proof. Nice! $\square$

Divisibility and Relatively Prime Integers

One of the real benefits of using relatively prime integers is that they let you conclude certain statements about divisibility which you might not usually get to make. For instance, if you are told that $a \mid bc$, you might be tempted to conclude that $a \mid b$ or $a \mid c$. In general, though, this is false (can you find a counterexample?). When you have some ''nice'' property involving relatively prime integers, however, you can call on a result such as this.

Lemma: If $(a,b) = 1$ and $a \mid bc$, then $a \mid c$.

I won't prove this for you now, since this is one of your homework exercises.

Least Common Multiples

GCD has a doppleganger hiding out in the shadows given by the so-called least common multiple

Definition: The least common multiple of two integers a and b, written [a,b], is the smallest number m such that $a \mid m$ and $b \mid m$.

Certainly common multiples of a and b exist, since ab is one such example. The game, then, is to find the smallest such integer.

Example: Computing an LCM

To find the least common multiple of 12 and 9, we write down multiples of each, stopping at $12 \cdot 9 = 108$

• the first few multiples of 12 are $\{12, 24, 36, 48, 60, 72, 84, 96, 108\}$, and
• the first few multiples of 9 are $\{9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108\}$.

From this we see that the smallest number which appears in both lists is 36, and so [12, 9] = 36.

The Relationship between LCM and GCD

One of the surprising results about the two concepts we've talked about today is that they are so closely related to each other, as witnessed by the following

Theorem: For any integers a and b, one has $(a,b)[a,b] = ab$.

We won't talk about the proof of this result in class, as it will later appear as a bonus problem for the first exam. One technique you might use to prove it, though, is by showing

1. that $\frac{ab}{(a,b)}$ is a common multiple of both a and b
2. that $\frac{ab}{(a,b)}$ divides any other common multiple of a and b

As an added bonus to this technique, you'll also have proven the following

Corollary: For any two integers a and b and any common multiple m of both, one has $[a,b] \mid m$.