The Euclidean Algorithm; Prime Numbers


Although we introduced the concept of greatest common divisors in class last time, we didn't come up with a very effective way of computing GCDs. We remedy this with the Euclidean Algorithm, and we show how this algorithm can also be used to express the GCD of two numbers a and b as an explicit linear combination of a and b. Afterwards we introduced prime numbers and started proving some results about them.

The Euclidean Algorithm

Greatest Common Divisors might seem like a boring subject to you, since likely you already saw GCDs when you were in high school. The kinds of GCDs you were after then — between pairs of numbers which are relatively small and easily factored — are quite different from the kinds of GCDs people care about in practice — namely between pairs of numbers which are much too large to easily factor. For this reason, we need a method for computing GCDs effeciently. The idea for this method comes from the remarkably simple

Lemma: Suppose that a and b are integers and that $a = qb + r$ as per the Division Algorithm. Then $(a,b) = (b,r)$.

Proof: This is really not a hard proof. Suppose that d is a common divisor of a and b. Then since $r = a-qb$, we have that d is a divisor of r as well (using our "divisibility of integral linear combinations" result).

Likewise, if d is a common divisor of b and r, then since $a = qb + r$ we have that d is also a divisor of a.

Hence all common divisors of a and b are also common divisors of b and r, and vice versa, proving that the greatest elements amongst these common divisors are the same. $\square$

We can apply this idea iteratively to give a computationally effective way to compute GCDs.

Example: Computing GCDs with the Euclidean Algorithm

Suppose you're interested in computing (1921,493). Using the previous result, since

\begin{align} 1921 = 3\cdot 493 + 442 \end{align}

we know that this GCD is the same as (493,442). In fact, we can keep using this result over and over again, provided we keep using the division algorithm every time we get a non-zero remainder. These applications of the division algorithm are:

\begin{align} \begin{split} 493 &= 1\cdot 442 + 51\\ 442 &= 8\cdot 51 + 34\\ 51 &= 1\cdot 34 + 17\\ 34 & = 2\cdot 17 + 0\\ \end{split} \end{align}

Hence we have

\begin{align} \begin{split} (1921,493) &= (493,442) = (442, 51) = (51,34) \\&= (34,17) = (17,0) = 17. \end{split} \end{align}

Example: Expressing GCD as a linear combo

This same procedure can be used to write the GCD between a and b as an integral linear combination of the two. In the previous computation, for instance, the second-to-last division algorithm application gives

\begin{align} 17 = 51 - 1\cdot 34 \end{align}

The previous application of the division algorithm, though, showed us that $34 = 442-8\cdot 51$, and hence we can substitute this into our expression for 17:

\begin{align} 17 = 51 - 1\cdot 34 = 51 - (442-8\cdot 51) = 9\cdot 51 - 442 \end{align}

Using the equality $51 = 493-442$ and substituting again gives

\begin{align} 17 = 9\cdot (493-442) - 442 = 9\cdot 493 - 10\cdot 442 \end{align}

Continuing this kind of back substitution gives

\begin{align} \begin{split} 17 &= 9\cdot 493 - 10\cdot 442\\ &=9\cdot 493 - 10\cdot (1921-3\cdot 493) = 39 \cdot 493 -10 \cdot 1921\\ \end{split} \end{align}

Prime Numbers

The stars of number theory are the prime numbers.

A number $p>1$ is said to be prime if the only positive divisors of p are 1 and itself. A number $n > 1$ is said to be composite if it is not prime; i.e., n is composite if there exist $1 < a,b < n$ so that $n = ab$.

The reason that prime numbers are so exciting is that, despite their foundational role in the multiplicative structure of the integers, they are very elusive. When I say that they are foundational in the multiplicative structure of the integers, I mean that any factorization of an integer n involves prime numbers as the atomic pieces — in the same way that any physical substance we encounter is built out of elements from the periodic table. This is made precise by the Fundamental Theorem of Arithmetic, a topic we'll start discussing tomorrow. And when I say elusive, I mean just that: the damn things are hard to pin down and understand. We'll talk more about both of these ideas — as well as some cool applications of primality — throughout the remainder of the course.

For now, though, we'll take a step in the first direction: showing that prime numbers are the building blocks of integers. For this, we begin with a nice lemma that says that any number is divisible by at least 1 prime number.

Lemma: For any integer $n>1$, there exists some prime number p which divides n.

Proof: We'll prove this result by contradiction: assuming the opposite of what we want to prove, manipulating this assumption until it reaches a contradiction, and then concluding that our assumption must be false — and hence our desired conclusion is true.

So suppose that not every integer n has a prime factor. This means that the set

\begin{align} S = \{1 < n \in \mathbb{Z}: p \nmid n \mbox{ for all primes }p\} \end{align}

is non-empty. As a non-empty set of positive integers, S must have a least element. We'll call this least element N.

Now N is an element of S, and hence has no prime divisor. Since N is a divisor of itself — $N \mid N$, after all — this means in particular that N cannot be prime. Therefore N is composite, meaning there exist integers $1 < a,b < N$ so that N = ab. Being positive integers less than N, both a and b must live outside of S, and hence each has a prime factor: say $p \mid a$ and $q \mid b$. But then $p \mid a$ and $a \mid N$, so that $p \mid N$, contrary to the defining property of N.

Having reached a contradiction, we conclude that S must, indeed, be empty, and so every integer greater than 1 has a prime factor. $\square$

This result gives us a method for finding prime numbers using a sieve technique. Before we get there, we need to first make the following

Observation: If $n>1$ is a composite number, then there exists a prime divisor p of n such that $p \leq \root\of{n}$.

Proof: If n is composite, then there exist integers a and b so that n = ab. Now one of a or b must be less than $\root\of{n}$, since otherwise their product would be greater than n. Without loss of generality, we can assume that $a \leq \root\of{n}$. Now a has a prime factor p from the previous lemma, and so $p \leq a \leq \root\of{n}$. Since $p \mid a$ and $a \mid n$, we further have $p \mid n$, giving the desired result.

A Sieve Example

The idea behind a sieve is to find prime numbers by eliminating multiples of known prime numbers. The magic, though, is that one has to use relatively few primes to sieve out larger ones.

Suppose, for instance, that you wanted to find all prime numbers less than 60. The previous observation says that any composite number $n \leq 60$ must have a prime factor which is smaller than $\root\of{n}\leq \root\of{60} < 8$. Hence any composite number smaller than 60 must be divisible by one of the primes which is smaller than 8 — namely one of 2, 3, 5, or 7. Hence if we listed all the numbers between 2 and 60 and crossed out the multiples of the primes listed above, the remaining numbers would all have to be prime. Let's try it out:

2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60

After crossing out all multiples of 2, 3, 5, and 7, we see that the primes less than 60 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 21, 37, 41, 43, 47, 53, and 59.

In the same way that knowing the primes less than $\root\of{60}$ gave us a method for finding the primes less than 60, knowing the list of primes less than n gives us a way to generate the list of primes less than $n^2$. While this is a great way to conclusively generate prime numbers, the downside is that this technique takes a LONG times to implement. Hence it is an effective but impractical method for finding really big prime numbers.

Asking Questions About Primes

Having actually gone through and found a handful of small primes, we now begin to wonder what can be said about primes. Here are a few basic questions you might want to know

  • how many primes are there? for instance, is the number of primes finite?
  • if the number of primes isn't finite, do we at least have a reasonable guess as to how many primes there are of a given magnitude?
  • do we know how "spread out" the prime numbers are? do they come in clusters, or should we expect that they are always far apart from each other?
  • is there a formula which allows us to quickly generate prime numbers?

These are all good questions, and some of them have nice, easy answers. Alternatively, some of these questions are exceedingly difficult to investigate. We'll cover a sampling in class tomorrow.

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License