46
Chapter 4 Number theory Number theory is one of the oldest branches of mathematics, and this chapter is intended to be just an introduction to a vast subject. I start by proving that essentially every integer can be written as a product of powers of primes, a result known as the fundamental theorem of arithmetic. This shows that the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the subject of intensive research and the source of many unanswered questions. It is ironic that the numbers we learn about first as children are the source of some of mathematics most difficult and interesting questions. 4.1 Greatest common divisors The ideas in this section are simple but their ramifications substantial. We begin by stating a basic result that you may assume as an axiom but which I shall also set as a proof in one of the exercises. Lemma 4.1.1 (Remainder Theorem). Let a and b be integers where b> 0. Then there are unique integers q and r such that a = bq + r where 0 r<b. The number q is called the quotient and the number r is called the re- mainder. For example, if we consider the pair of natural numbers 14 and 3 then 14 = 3 · 4+2 81

Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

Chapter 4

Number theory

Number theory is one of the oldest branches of mathematics, and this chapteris intended to be just an introduction to a vast subject. I start by provingthat essentially every integer can be written as a product of powers of primes,a result known as the fundamental theorem of arithmetic. This shows thatthe primes are the building blocks, or atoms, from which all integers areconstructed. The primes are still the subject of intensive research and thesource of many unanswered questions. It is ironic that the numbers we learnabout first as children are the source of some of mathematics most difficultand interesting questions.

4.1 Greatest common divisors

The ideas in this section are simple but their ramifications substantial. Webegin by stating a basic result that you may assume as an axiom but whichI shall also set as a proof in one of the exercises.

Lemma 4.1.1 (Remainder Theorem). Let a and b be integers where b > 0.Then there are unique integers q and r such that

a = bq + r

where 0 ≤ r < b.

The number q is called the quotient and the number r is called the re-mainder. For example, if we consider the pair of natural numbers 14 and 3then

14 = 3 · 4 + 2

81

Page 2: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

82 CHAPTER 4. NUMBER THEORY

where 4 is the quotient and 2 is the remainder. Your first reaction to thisresult should probably be that it looks obvious. You might conclude fromthis that it is therefore uninteresting. But this would be wrong. It is certainlynot hard to understand but despite that it is important. The reason is thatwhenever we have a question that involves divisibility, it is very likely goingto require the use of this result.

Example 4.1.2. From the remainder theorem, we know that every naturalnumber n can be written as n = 10q + r where 0 ≤ r ≤ 9. The integer r isnothing other than the units digit in the usual base 10 representation of n.Thus, for example, 42 = 10 × 4 + 2. Similarly, it is the remainder theoremthat tells us that odd numbers are precisely those that leave remainder 1when divided by 2.

Let a and b be integers. We say that a divides b or that b is divisible bya if there is a q such that b = aq. In other words, there is no remainder. Wealso say that a is a divisor or factor of b. We write a | b to mean the samething as ‘a divides b’. It is very important to remember that a | b does notmean the same thing as a

b. The latter is a number, the former is a statement

about two numbers.

Let a, b ∈ N. A number d which divides both a and b is called a commondivisor of a and b. The largest number which divides both a and b is calledthe greatest common divisor of a and b and is denoted by gcd(a, b). A pairof natural numbers a and b is said to be coprime if gcd(a, b) = 1. For usgcd(0, 0) is undefined but if a 6= 0 then gcd(a, 0) = a.

Example 4.1.3. Consider the numbers 12 and 16. The set of divisors of12 is {1, 2, 3, 4, 6, 12}. The set of divisors of 16 is {1, 2, 4, 8, 16}. The set ofcommon divisors is the set of numbers that belong to both of these two sets:namely, {1, 2, 4}. The greatest common divisor of 12 and 16 is therefore 4.Thus gcd(12, 16) = 4.

One application of greatest common divisors is in simplifying fractions.For example, the fraction 12

16is equal to the fraction 3

4because we can divide

out by the common divisor of numerator and denominator. The fractionwhich results cannot be simplified further and is in its lowest terms.

Lemma 4.1.4. Let d = gcd(a, b). Then gcd(ad, bd) = 1.

Page 3: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.1. GREATEST COMMON DIVISORS 83

Proof. Because d divides both a and b we may write a = a′d and b = b′d forsome natural numbers a′ and b′. We therefore need to prove that gcd(a′, b′) =1. Suppose that e | a′ and e | b′. Then a′ = ex and b′ = ey for some naturalnumbers x and y. Thus a = exd and b = eyd. Observe that ed | a and ed | band so ed is a common divisor of both a and b. But d is the greatest commondivisor and so e = 1, as required.

Let me paraphrase what the result above says since it is not surprising. IfI divide two numbers by their greatest common divisor then the numbers thatremain are coprime. This seems intuitively plausible and the proof ensuresthat our intuition is correct.

Example 4.1.5. Greatest common divisors arise naturally in solving lin-ear equations where we require the solutions to be integers. Consider, forexample, the linear equation

12x+ 16y = 5.

If we want our solutions (x, y) to have real number co-ordinates, then it isof course easy to solve this equation and find infinitely many solutions sincethe solutions form a line in the plane. But suppose now that we require(x, y) ∈ Z2; that is, we want the solutions to be integers. In other words, wewant to know whether the line contains any points with integer co-ordinates.We can see immediately that this is impossible. We have calculated thatgcd(12, 16) = 4. Thus if x and y are integers, the number 4 divides thelefthand side of our equation. But clearly, 4 does not divide the righthandside of our equation. Thus the set

{(x, y) : (x, y) ∈ Z2and 12x+ 16y = 5}

is empty.

If the numbers a and b are large, then calculating their gcd in the wayI did above would be time-consuming and error-prone. We want to find anefficient method of calculating the greatest common divisor. The followinglemma is the basis of just such a method.

Lemma 4.1.6. Let a, b ∈ N, where b 6= 0, and let a = bq+r where 0 ≤ r < b.Then

gcd(a, b) = gcd(b, r).

Page 4: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

84 CHAPTER 4. NUMBER THEORY

Proof. Let d be a common divisor of a and b. Since a = bq + r we have thata− bq = r so that d is also a divisor of r. It follows that any divisor of a andb is also a divisor of b and r.

Now let d be a common divisor of b and r. Since a = bq+ r we have thatd divides a. Thus any divisor of b and r is a divisor of a and b.

It follows that the set of common divisors of a and b is the same as theset of common divisors of b and r. Thus gcd(a, b) = gcd(b, r).

The point of the above result is that b < a and r < b. So calculat-ing gcd(b, r) will be easier than calculating gcd(a, b) because the numbersinvolved are smaller. Compare

︷ ︸︸ ︷a = b q + r

witha = bq + r︸ ︷︷ ︸ .

The above result is the basis of an efficient algorithm for computing greatestcommon divisors. It was described in Propositions 1 and 2 of Book VII ofEuclid.

Algorithm 4.1.7 (Euclid’s algorithm).Input: a, b ∈ N such that a ≥ b and b 6= 0.Output: gcd(a, b).Procedure: write a = bq + r where 0 ≤ r < b. Then gcd(a, b) = gcd(b, r). Ifr 6= 0 then repeat this procedure with b and r and so on. The last non-zeroremainder is gcd(a, b)

Example 4.1.8. Let’s calculate gcd(19, 7) using Euclid’s algorithm. I havehighlighted the numbers that are involved at each stage.

19 = 7 · 2 + 5

7 = 5 · 1 + 2

5 = 2 · 2 + 1 ∗2 = 1 · 2 + 0

By Lemma 1.3.3 we have that

gcd(19, 7) = gcd(7, 5) = gcd(5, 2) = gcd(2, 1) = gcd(1, 0).

The last non-zero remainder is 1 and so gcd(19, 7) = 1 and, in this case, thenumbers are coprime.

Page 5: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.1. GREATEST COMMON DIVISORS 85

There are occasions when we need to extract more information from Eu-clid’s algorithm as we shall discover later when we come to deal with primenumbers. The following provides what we need.

Theorem 4.1.9 (Bezout’s theorem). Let a and b be natural numbers. Thenthere are integers x and y such that

gcd(a, b) = xa+ yb.

I shall prove this theorem by describing an algorithm that will computethe integers x and y above. This is achieved by running Euclid’s algorithmin reverse and is called the extended Euclidean algorithm. The procedure fordoing so is outlined below but the details are explained in the example thatfollows it.

Algorithm 4.1.10 (Extended Euclidean algorithm).Input: a, b ∈ N where a ≥ b and b 6= 0.Output: numbers x, y ∈ Z such that gcd(a, b) = xa+ yb.Procedure: apply Euclid’s algorithm to a and b; working from bottom to toprewrite each remainder in turn.

Example 4.1.11. This is a little involved so I have split the process upinto steps. I shall apply the extended Euclidean algorithm to the example Icalculated above. I have highlighted the non-zero remainders wherever theyoccur, and I have discarded the last equality where the remainder was zero.I have also marked the last non-zero remainder.

19 = 7 · 2 + 5

7 = 5 · 1 + 2

5 = 2 · 2 + 1 ∗

The first step is to rearrange each equation so that the non-zero remainderis alone on the lefthand side.

5 = 19− 7 · 22 = 7− 5 · 11 = 5− 2 · 2

Page 6: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

86 CHAPTER 4. NUMBER THEORY

Next we reverse the order of the list

1 = 5− 2 · 22 = 7− 5 · 15 = 19− 7 · 2

We now start with the first equation. The lefthand side is the gcd we areinterested in. We treat all other remainders as algebraic quantities and sys-tematically substitute them in order. Thus we begin with the first equation

1 = 5− 2 · 2.

The next equation in our list is

2 = 7− 5 · 1

so we replace 2 in our first equation by the expression on the right to get

1 = 5− (7− 5 · 1) · 2.

We now rearrange this equation by collecting up like terms treating the high-lighted remainders as algebraic objects to get

1 = 3 · 5− 2 · 7.

We can of course make a check at this point to ensure that our arithmetic iscorrect. The next equation in our list is

5 = 19− 7 · 2

so we replace 5 in our new equation by the expression on the right to get

1 = 3 · (19− 7 · 2)− 2 · 7.

Again we rearrange to get

1 = 3 · 19 − 8 · 7 .

The algorithm now terminates and we can write

gcd(19, 7) = 3 · 19 + (−8) · 7 ,

as required. We can also, of course, easily check the answer!

Page 7: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.1. GREATEST COMMON DIVISORS 87

I shall describe a much more efficient algorithm for implementing theextended Euclidean algorithm later in this book when I have discussed ma-trices.

A very useful application of Bezout’s theorem is the following.

Lemma 4.1.12. Let a and b be natural numbers. Then a and b are coprimeif, and only if, we may find integers x and y such that

1 = xa+ yb.

Proof. Suppose first that a and b are coprime. Then by Bezout’s theorem

gcd(a, b) = ax+ by

for some integers a and b. But, by assumption, gcd(a, b) = 1. Conversely,suppose that

1 = xa+ yb.

Then any natural number that divides both a and b must divide 1. It followsthat gcd(a, b) = 1.

The significance of the above lemma is that whenever you know that aand b are coprime, you can actually write down an expression 1 = xa + ybwhich means the same thing. This turns out to be enormously useful.

The greatest common divisor of two numbers a and b is the largest numberthat divides into both a and b. On the other hand, if a | c and b | c then wesay that c is a common multiple of a and b. The smallest common multipleof a and b is called the least common multiple of a and b and is denoted bylcm(a, b). You might expect that to calculate the least common multiple wewould need a new algorithm, but in fact we can use Euclid’s algorithm asthe following result shows. I shall prove the following result later once I haveproved the fundamental theorem of arithmetic.

Proposition 4.1.13. Let a and b be natural numbers. Then

gcd(a, b)× lcm(a, b) = ab.

The notions of gcd and lcm play a natural role in the arithmetic of frac-tions. The key property of fractions is that a fraction a

bis unchanged when

numerator and denominator are both multiplied by the same non-zero inte-ger. Thus

a

b=ac

bc.

Page 8: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

88 CHAPTER 4. NUMBER THEORY

Given a fraction ab

we often want to simplify it as much as possible and thisis accomplished by calculating gcd(a, b) = d. We have a = a′d and b = b′dand so

a

b=a′d

b′d=a′

b′.

We have proved above that gcd(a′, b′) = 1 and so the fraction cannot besimplified any further. Thus a′

b′ is a fraction in its lowest terms. When wecome to add fractions, the problem is the reverse of simplification. We cannotimmediately add a

b+ c

dbecause the denominators b and d are different. To

make progress, we have to rewrite each fraction so that their denominatorsare the same. The simplest way to do this is to rewrite each fraction as afraction over bd by multiplying the first fraction by d and the second by b toget

ad

bd+bc

bd=ad+ bc

bd.

However, the most efficient way is to write each fraction over lcm(b, d). Letlcm(b, d) = b′b = d′d. Then

a

b+c

d=b′a

b′b+d′c

d′d=b′a+ d′c

lcm(b, c).

Exercises 4.1

1. Find the quotients and remainders for each of the following pair ofnumbers. Divide the smaller into the larger.

(a) 30 and 6.

(b) 100 and 24.

(c) 364 and 12.

2. Use Euclid’s algorithm to find the gcd’s of the following pairs of num-bers.

(a) 35, 65.

(b) 135, 144.

(c) 17017, 18900.

Page 9: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.1. GREATEST COMMON DIVISORS 89

3. Use the extended Euclidean algorithm to find integers x and y suchthat gcd(a, b) = ax+by for each of the following pairs of numbers. Youshould ensure that your answers for x and y have the correct signs.

(a) 112, 267.

(b) 242, 1870.

4. Find the lowest common multiples of the following pairs of numbers.

(a) 22, 121.

(b) 48, 72.

(c) 25, 116.

5. We know how to find the greatest natural number that divides twonumbers. Define now gcd(a, b, c) to be the greatest common divisor ofa and b and c jointly. Prove that

gcd(a, b, c) = gcd(gcd(a, b), c).

Deduce thatgcd(gcd(a, b), c) = gcd(a, gcd(b, c)).

We may similarly define gcd(a, b, c, d) to be the greatest common divisorof a and b and c and d jointly. Calculate gcd(910, 780, 286, 195) andjustify your calculations.

6. The following question is by Dubisch Amer. Math. Mon. 69. DefineN∗ = N \ {0}. A binary operation ◦ defined on N∗ is known to havethe following properties:

(a) a ◦ b = b ◦ a.

(b) a ◦ a = a.

(c) a ◦ (a+ b) = a ◦ b.Prove that a ◦ b = gcd(a, b). Hint: the question is not asking you toprove that gcd(a, b) has these properties.

7. You have an unlimited supply of 3 cent stamps and an unlimited supplyof 5 cent stamps. By combining stamps of different values you can makeup other values: for example, three 3 cent stamps and two 5 cent stampsmake the value 19 cents. What is the largest value you cannot make?Hint: you need to show that the question makes sense.

Page 10: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

90 CHAPTER 4. NUMBER THEORY

8. Let n ≥ 1. Define φ(n) to be the number of numbers less than or equalto n and coprime to n. This is the Euler totient function. Tabulate thevalues of φ(n) for 1 ≤ n ≤ 12.

9. Prove the following properties of the division relation on Z.

(a) If a 6= 0 then a | a.

(b) If a | b and b | a then a = ±b.(c) If a | b and b | c then a | c.(d) If a | b and a | c then a | (b+ c).

10. This question develops a proof of the remainder theorem. Let a andb be integers with b > 0. Then there exist a unique pair of integers qand r such that a = qb+ r where 0 ≤ r < b.

(a) Let

X = {a− nb : n ∈ Z}.Show that this set contains non-negative elements.

(b) Let X+ be the subset of X consisting of non-negative elements.This subset is non-empty by the first step. Use the well-orderingprinciple to deduce that this set contains a minimum element r.Thus r = a− qb ≥ 0 for some q ∈ Z.

(c) Show that if r ≥ b then X+ in fact contains a smaller element,which is a contradiction.

(d) We therefore have that a = bq + r where 0 ≤ r < b. It remainsto prove that q and r are unique with these propertries. Assumetherefore that a = bq′ + r′ where 0 ≤ r′ < b. Deduce that q = q′

and r = r′.

4.2 The fundamental theorem of arithmetic

The goal of this section is to state and prove the most basic result about thenatural numbers: each natural number, excluding 0 and 1, can be writtenas a product of powers of primes in essentially one way. The primes aretherefore the ‘atoms’ from which all natural numbers can be built.

Page 11: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.2. THE FUNDAMENTAL THEOREM OF ARITHMETIC 91

A proper divisor of a natural number n is a divisor that is neither 1 norn. A natural number n is said to be prime if n ≥ 2 and the only divisors ofn are 1 and n itself. A number bigger than or equal to 2 which is not primeis said to be composite. It is important to remember that the number 1 isnot a prime. The only even prime is the number 2.

The properties of primes have exercised a great fascination ever since theywere first studied and continue to pose questions that mathematicians haveyet to solve. There are no nice formulae to tell us what the nth prime is butthere are still some interesting results in this direction. The polynomial

p(n) = n2 − n+ 41

has the property that its value for n = 1, 2, 3, 4, . . . , 40 is always prime. Ofcourse, for n = 41 it is clearly not prime. In 1971, the mathematician YuriMatijasevic found a polynomial in 26 variables of degree 25 with the propertythat when non-negative integers are substituted for the variables the positivevalues it takes are all and only the primes. However, this polynomial doesnot generate the primes in any particular order.

Lemma 4.2.1. Let n ≥ 2. Either n is prime or the smallest proper divisorof n is prime.

Proof. Suppose n is not prime. Let d be the smallest proper divisor of n. If dwere not prime then d would have a smallest proper divisor and this divisorwould in turn divide n, but this would contradict the fact that d was thesmallest proper divisor of n. Thus d must itself be prime.

The following was also proved by Euclid: it is Proposition 20 of Book IXof Euclid.

Theorem 4.2.2. There are infinitely many primes.

Proof. Let p1, . . . , pn be the first n primes. Put

N = (p1 . . . pn) + 1.

If N is a prime, then N is a prime bigger than pn. If N is composite, then Nhas a prime divisor p by Lemma 4.2.1. But p cannot equal any of the primesp1, . . . , pn because N leaves remainder 1 when divided by pi. It follows thatp is a prime bigger than pn. Thus we can always find a bigger prime. Itfollows that there must be an infinite number of primes.

Page 12: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

92 CHAPTER 4. NUMBER THEORY

Algorithm 4.2.3. To decide whether a number n is prime or composite.Check to see if any prime p ≤ √n divides n. If none of them do, the numbern is prime. We shall now explain why this works. If a divides n then we canwrite n = ab for some number b. If a <

√n then b >

√n whilst if a >

√n

then b <√n. Thus to decide if n is prime or not we need only carry out trial

divisions by all numbers a ≤ √n. However, this is inefficient because if adivides n and a is not prime then a is divisible by some prime p which musttherefore also divide n. It follows that we need only carry out trial divisionsby the primes p ≤ √n.

Example 4.2.4. Determine whether 97 is prime using the above algorithm.We first calculate the largest whole number less than or equal to

√97. This

is 9. We now carry out trial divisions of 97 by each prime number p where2 ≤ p ≤ 9; by the way, if you aren’t certain which of these numbers is prime:just try them all. You’ll get the right answer although not as efficiently. Youmight also want to remember that if m doesn’t divide a number neither canany multiple of m. In any event, in this case we carry out trial divisions by2, 3, 5 and 7. None of them divides 97 exactly and so 97 is prime.

The following is the key property of primes we shall need to prove thefundamental theorem of arithmetic. It is the main reason why we neededBezout’s theorem. It is Proposition 30 of Book VII of Euclid.

Lemma 4.2.5 (Euclid’s lemma). Let p | ab where p is a prime. Then p | aor p | b.Proof. Suppose that p does not divide a. We shall prove that p must thendivide b. If p does not divide a, then a and p are coprime. By Lemma 4.1.12,there exist integers x and y such that 1 = px+ay. Thus b = bpx+ bay. Nowp | bp and p | ba, by assumption, and so p | b, as required.

Example 4.2.6. The above result is not true if p is not a prime. For example,6 | 9× 4 but 6 divides neither 9 nor 4.

Lemma 4.2.5 is so important, I want to spell out in words what it says:

If a prime divides a product of numbers it must divide at leastone of them.

There is a very nice application of Euclid’s lemma to proving that certainnumbers are irrational. It generalizes our proof that

√2 is irrational described

in Chapter 2.

Page 13: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.2. THE FUNDAMENTAL THEOREM OF ARITHMETIC 93

Theorem 4.2.7. The square root of every prime number is irrational.

Proof. We shall prove this by contradiction. Assume that we can write√p

as a rational. I shall show that this assumption leads to a contradiction andso must be false. We are assuming that

√p = a

b. By cancelling the greatest

common divisor of a and b we can in fact assume that gcd(a, b) = 1. Thiswill be crucial to our argument. Squaring both sides of the equation

√p = a

b

and multiplying the resulting equation by b2 we get that

pb2 = a2.

This says that a2 is divisible by p. But if a prime divides a product of twonumbers it must divide at least one of those numbers by Euclid’s lemma.Thus p divides a. Thus we can write a = pc for some natural number c.Substituting this into our equation above we get that

pb2 = p2c2.

Dividing both sides of this equation by p gives

b2 = pc2.

This tells us that b2 is divisible by p and so in the same way as above pdivides b. We have therefore shown that our assumption that

√p is rational

leads to both a and b being divisible by p. But this contradicts the fact thatgcd(a, b) = 1. Our assumption is therefore wrong, and so

√p is not a rational

number.

We now come to the main theorem of this chapter.

Theorem 4.2.8 (Fundamental theorem of arithmetic). Every number n ≥ 2can be written as a product of primes in one way if we ignore the order inwhich the primes appear. By product we allow the possibility that there isonly one prime.

Proof. Let n ≥ 2. If n is already a prime then there is nothing to prove, sowe can suppose that n is composite. Let p1 be the smallest prime divisor ofn. Then we can write n = p1n

′ where n′ < n. Once again, n′ is either primeor composite. Continuing in this way, we can write n as a product of primes.

We now prove uniqueness. Suppose that

n = p1 . . . ps = q1 . . . qt

Page 14: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

94 CHAPTER 4. NUMBER THEORY

are two ways of writing n as a product of primes. Now p1 | n and so p1 |q1 . . . qt. By Euclid’s Lemma, the prime p1 must divide one of the qi’s and,since they are themselves prime, it must actually equal one of the qi’s. Byrelabelling if necessary, we can assume that p1 = q1. Cancel p1 from bothsides and repeat with p2. Continuing in this way, we see that every primeoccurring on the lefthand side occurs on the righthand side. Changing sides,we see that every prime occurring on the righthand side occurs on the lefthandside. We deduce that the two prime decompositions are identical.

When we write a number as a product of primes we usually gather to-gether the same primes into a prime power, and write the primes in increasingorder which then gives a unique representation. This is illustrated in the ex-ample below.

Example 4.2.9. Let n = 999, 999. Write n as a product of primes. Thereare a number of ways of doing this but in this case there is an obvious placeto start. We have that

n = 32 ·111, 111 = 33 ·37, 037 = 33 ·7 ·5, 291 = 33 ·7 ·11 ·481 = 33 ·7 ·11 ·13 ·37.

Thus the prime factorisation of 999, 999 is

999, 999 = 33 · 7 · 11 · 13 · 37.

We can use the prime factorizations of numbers to give a nice proof ofProposition 4.1.13. Let m and n be two integers. To keep things simple, wesuppose that their prime factorizations are

m = pα1pβ2p

γ3 and n = pδ1p

ε2pζ3

where p1, p2, p3 are primes. It will be obvious how to extend this argumentto the general case. The prime factorizations of gcd(m,n) and lcm(m,n) are

gcd(m,n) = pmin(α,δ)1 p

min(β,ε)2 p

min(γ,ζ)3

andlcm(m,n) = p

max(α,δ)1 p

max(β,ε)2 p

max(γ,ζ)3

respectively. I shall let you work out why and also work out how we can usethese results to prove the above proposition.

Page 15: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.2. THE FUNDAMENTAL THEOREM OF ARITHMETIC 95

The Prime Number Theorem

There are no formulae which output the nth prime in a usable way, butif we adopt a statistical approach then we can obtain much more usefulresults. The idea is that for each natural number n we count the numberof primes π(n) less than or equal to n. The graph of π(n) has a staircaseshape — it certainly isn’t smooth — but as you zoom away it begins tolook smoother and smoother. This raises the question whether there isa smooth function that is a good approximation to π(n). In 1792, theyoung Carl Friedrich Gauss (1777–1855) observed that π(n) appeared tobe close to the value of the amazingly simple function n

ln(n). But proving

that this was always true, and not just an artefact of the comparativelysmall numbers he looked at, turned out to be difficult. Eventually,in 1896 two mathematicians, Jacques Hadamard (1865–1963) and thespectacularly named Charles Jean Gustave Nicolas Baron de la ValleePoussin (1866–1962), proved independently of each other that

limx→∞

π(x)

x/ ln(x)= 1

a result known as the Prime Number Theorem. It was proved usingcomplex analysis; that is, calculus using complex numbers.

Cryptography

Prime numbers also play an important role in computing: specifically,in exchanging secret information. In 1976, Whitfield Diffie and MartinHellman wrote a paper on cryptography that can genuinely be calledground-breaking. In ‘New directions in cryptography’ IEEE Transac-tions on Information Theory 22 (1976), 644–654, they put forward theidea of a public-key cryptosystem which would enable

. . . a private conversation . . . [to] be held between any two in-dividuals regardless of whether they have ever communicatedbefore.

With considerable farsightedness, Diffie and Hellman foresaw that suchcryptosystems would be essential if communication between computers

Page 16: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

96 CHAPTER 4. NUMBER THEORY

was to reach its full potential. However, their paper did not describe aconcrete way of doing this. It was R. I. Rivest, A. Shamir and L. Adle-man (RSA) who found just such a concrete method described in theirpaper, ‘A method for obtaining digital signatures and public-key cryp-tosystems’ Communications of the ACM 21 (1978), 120–126. Theirmethod is based on the following observation. Given two prime num-bers it takes very little time to multiply them together, but if I give youa number that is a product of two primes and ask you to factorize it thenit takes a lot of time. After considerable experimentation, RSA showedhow to use little more than undergraduate mathematics to put togethera public-key cryptosystem that is an essential ingredient in e-commerce.Ironically, this secret code had in fact been invented in 1973 at GCHQ,who had kept it secret.

Supernatural Numbers

There are natural numbers. Are there super natural numbers? It soundslike a joke but in fact there are, though to be honest they are onlyencountered in advanced work. But since they are easy to understandand I like the name, I have included a brief description List the primesin order 2, 3, 5, 7, . . .. By the fundamental theorem of arithmetic, eachnatural number ≥ 2 may be expressed as a unique product of powers ofprimes. Let’s write each such natural number as a product all primes.This can be achieved by including those primes not needed by raisingthem to the power 0. For example,

10 = 2 · 5 = 21 · 30 · 51 · 70 . . .

which we could write as

(1, 0, 1, 0, 0, 0 . . .)

and12 = 22 · 3 = 22 · 31 · 50 · 70 . . .

which we could write as

(2, 1, 0, 0, 0, 0 . . .)

Page 17: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.2. THE FUNDAMENTAL THEOREM OF ARITHMETIC 97

Of course, for each natural number from some point on all the entrieswill be zero. Thus each natural number ≥ 2 is encoded by an infinitesequence of natural numbers that are zero from some point onwards.We now define a supernatural number to be any sequence

(a1, a2, a3, . . .)

where the ai are natural numbers. We define a natural number to be asupernatural number where the ai = 0 for all i ≥ m for some naturalnumber m ≥ 1. This makes sense because each natural supernaturalnumber can be regarded as the encoded version of a natural number inthe non-super sense. I shall denote the set of supernatural numbers byS; this is not yet the complete list since I still have to add some specialsuch numbers. I shall denote supernatural numbers by bold letters suchas a. I shall also denote the ith component by ai. Let a and b be twosupernatural numbers. We define their product as follows

(a · b)i = ai + bi.

This makes sense because, for example,

10 · 12 = 120

and

(1, 0, 1, 0, 0, 0 . . .) · (2, 1, 0, 0, 0, 0 . . .) = (3, 1, 1, 0, 0, 0 . . .)

which encodes 233151 = 120. I shall leave you to check that the multi-plication is associative. If we define

1 = (0, 0, 0, . . .)

and allow it to be supernatural then we also have a multiplicative iden-tity because

1 · a = a = a · 1.Now introduce a new symbol ∞ which satisfies a +∞ = ∞ = ∞ + a.Then if we allow

0 = (∞,∞,∞, . . .)

Page 18: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

98 CHAPTER 4. NUMBER THEORY

as a supernatural number then we also have a zero in the set of super-natural numbers since

0 · a = 0 = a · 0.Finally, allow ∞ to occur anyway any number of times in the definitionof a supernatural number. Then we have the full set of supernaturalnumbers. How do you think that we could define gcd(a,b) and lcm(a,b)of supernatural numbers?

Exercises 4.2

1. List the primes less than 100. Hint: use the Sieve of Eratosthenes1

which can be used to construct a table of all primes up to the numberN . List all numbers from 2 to N inclusive. Mark 2 as prime and thencross out from the table all numbers which are multiples of 2. Theprocess now iterates as follows. Find the smallest number which is notmarked as a prime and which has not been crossed out. Mark it as aprime and cross out all its multiples. If no such number can be foundthen you have found all primes less than or equal to N .

2. For each of the following numbers use Algorithm 4.2.3 to determinewhether they are prime or composite. When they are composite find aprime factorization. Show all working.

(a) 131.

(b) 689.

(c) 5491.

3. Given 24 · 3 · 55 · 112 and 22 · 56 · 114, calculate their greatest commondivisor and least common multiple.

4. Use the fundamental theorem of arithmetic to show that we can alwayswrite

√n, where n is a natural number, as a product of a natural

number and a product of square roots of primes. Calculate the squareroots of the following numbers exactly using the above method.

1Eratosthenes of Cyrene who lived about 250 BCE. He is famous for using geometryand some simple observations to estimate the circumference of the earth.

Page 19: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.3. WRITING NUMBERS DOWN 99

(a) 10.

(b) 42.

(c) 54.

5. Let a and b be coprime. Prove that if a | bc then a | c.

4.3 Writing numbers down

We begin at the beginning by reviewing how numbers are dealt with graph-ically.

4.3.1 From tallies to the positional number system

I don’t think our hunter-gatherer ancestors worried too much about writingnumbers down because there wasn’t any need: they didn’t have to fill intax-returns and so didn’t need accountants. However, organizing cities doesneed accountants and so ways had to be found of writing numbers down.The simplest way of doing this is to use a mark like |, called a tally, for eachthing being counted. So

||||||||||means 10 things. This system has advantages and disadvantages. The ad-vantage is that you don’t have to go on a training course to learn it. Thedisadvantage is that even quite small numbers need a lot of space like

||||||||||||||||||||||||||||||||||||||

It’s also hard to tell whether

|||||||||||||||||||||||||||||||||||||||

is the same number or not. (It’s not.) It’s inevitable that people will in-troduce abbreviations to make the system easier to use. Perhaps it was inthis way that the next development occurred. Both the ancient Egyptiansand Romans used similar systems but I’ll describe the Roman system becauseit involves letters rather than pictures. First, you have a list of basic symbols:

number 1 5 10 50 100 500 1000symbol I V X L C D M

Page 20: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

100 CHAPTER 4. NUMBER THEORY

There are more symbols for bigger numbers. Numbers are then writtenaccording to the additive principle. Thus MMVIIII is 2009. Incidently, Iunderstand that the custom of also using a subtractive principle so that, forexample, IX means 9 rather than using VIIII, is a more modern innovation.This system is clearly a great improvement on the tally-system. Even quitebig numbers are written compactly and it is easy to compare numbers. Onthe other hand, there is more to learn. The other disadvantage is that we needseparate symbols for different powers of 10 and their multiples by 5. Thiswas probably not too inconvenient in the ancient world where it is likely thatthe numbers needed on a day-to-day basis were never going to be that big.A common criticism of this system is that it is hard to do multiplication in.However, that turns out to be a non-problem because, like us, the Romansused pocket calculators or, more accurately, a device called an abacus thatcould easily be carried under a toga. The real evidence for the usefulness ofthis system of writing numbers is that it survived for hundreds and hundredsof years.

The system used throughout the world today is quite different and iscalled the positional number system. It seems to have been in place by theninth century in India but it was hundreds of years in development and theresult of ideas from many different cultures: the invention of zero on its ownis one of the great steps in human intellectual development. The genius ofthe system is that it requires only 10 symbols

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

and every natural number can be written using a sequence of these symbols.The trick to making the system work is that we use the position on the pageof a symbol to tell us what number it means. Thus 2009 means

103 102 101 100

2 0 0 9

In other words

2× 103 + 0× 102 + 0× 101 + 9× 100.

Notice the important role played by the symbol 0 which makes it clear towhich column a symbol belongs otherwise we couldn’t tell 29 from 209 from

Page 21: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.3. WRITING NUMBERS DOWN 101

2009. The disadvantage of this system is that you do have to go on a courseto learn it because it is a highly sophisticated way of writing numbers. On theother hand, it has the enormous advantage that any number can be writtendown in a compact way. Once the basic system had been accepted it couldbe adapted to deal not only with positive whole numbers but also negativewhole numbers, using the symbol −, and also fractions with the introductionof the decimal point. By the end of the sixteenth century, the full decimalsystem was in place.

Notation warning! In the UK, we use a raised decimal point like 0 · 123and not a comma. Also we generally write the number 1 without a longhook at the top. If you do write it like that there is a danger that people willconfuse it with the number 7 which is not always written in the UK with aline through it.

4.3.2 Number bases

We shall now look in more detail at the way in which numbers can be writtendown using a positional notation. In order not to be biased, we shall not justwork in base 10 but show how any base can be used. Our main tool is theremainder theorem.

Let’s see how to represent numbers in base b where b ≥ 2. If d ≤ 10 thenwe represent numbers by sequences of symbols taken from the set

Zd = {0, 1, 2, 3, . . . d− 1}

but if d > 10 then we need new symbols for 10, 11, 12 and so forth. It’sconvenient to use A,B,C, . . .. For example, if we want to write numbers inbase 12 we use the set of symbols

{0, 1, . . . , 9, A,B}

whereas if we work in base 16 we use the set of symbols

{0, 1, . . . , 9, A,B,C,D,E, F}.

If x is a sequence of symbols then we write xd to make it clear that we areto interpret this sequence as a number in base d. Thus BAD16 is a numberin base 16.

Page 22: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

102 CHAPTER 4. NUMBER THEORY

The symbols in a sequence xd, reading from right to left, tell us the con-tribution each power of d such as d0, d1, d2, etc makes to the number thesequence represents. Here are some examples.

Examples 4.3.1. Converting from base d to base 10.

1. 11A912 is a number in base 12. This represents the following numberin base 10:

1× 123 + 1× 122 + A× 121 + 9× 120,

which is just the number

123 + 122 + 10× 12 + 9 = 2001.

2. BAD16 represents a number in base 16. This represents the followingnumber in base 10:

B × 162 + A× 161 +D × 160,

which is just the number

11× 162 + 10× 16 + 13 = 2989.

3. 55567 represents a number in base 7. This represents the followingnumber in base 10:

5× 73 + 5× 72 + 5× 71 + 6× 70 = 2001.

These examples show how easy it is to convert from base d to base 10.

There are two ways to convert from base 10 to base d.

1. The first runs in outline as follows. Let n be the number in base 10that we wish to write in base d. Look for the largest power m of d suchthat adm ≤ n where a < d. Then repeat for n − adm. Continuing inthis way, we write n as a sum of multiples of powers of d and so we canwrite n in base d.

Page 23: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.3. WRITING NUMBERS DOWN 103

2. The second makes use of the remainder theorem. The idea behind thismethod is as follows. Let

n = am . . . a1a0

in base d. We may think of this as

n = (am . . . a1)d+ a0

It follows that a0 is the remainder when n is divided by d, and thequotient is n′ = am . . . a1. Thus we can generate the digits of n in based from right to left by repeatedly finding the next quotient and nextremainder by dividing the current quotient by d; the process starts withour input number as first quotient.

Examples 4.3.2. Converting from base 10 to base d.

1. Write 2001 in base 7. I’ll solve this question in two different ways: thelong but direct route and then the short but more thought-provokingroute.

We see that 74 > 2001. Thus we divide 2001 by 73. This goes 5 timesplus a remainder. Thus 2001 = 5 × 73 + 286. We now repeat with286. We divide it by 72. It goes 5 times again plus a remainder. Thus286 = 5× 72 + 41. We now repeat with 41. We get that 41 = 5× 7 + 6.We have therefore shown that

2001 = 5× 73 + 5× 72 + 5× 7 + 6.

Thus 2001 in base 7 is just 5556.

Now for the short method.

quotient remainder

7 20017 285 67 40 57 5 5

0 5

Thus 2001 in base 7 is:5556.

Page 24: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

104 CHAPTER 4. NUMBER THEORY

2. Write 2001 in base 12.

quotient remainder

12 200112 166 912 13 10 = A12 1 1

0 1

Thus 2001 in base 12 is:11A9.

3. Write 2001 in base 2.

quotient remainder

2 20012 1000 12 500 02 250 02 125 02 62 12 31 02 15 12 7 12 3 12 1 1

0 1

Thus 2001 in base 2 is (reading from bottom to top):

11111010001.

When converting from one base to another it is always wise to checkyour calculations by converting back.

Number bases have some special terminology associated with them whichyou might encounter:

Base 2 binary.

Base 8 octal.

Page 25: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.3. WRITING NUMBERS DOWN 105

Base 10 decimal.

Base 12 duodecimal.

Base 16 hexadecimal.

Base 20 vigesimal.

Base 60 sexagesimal.

Binary, octal and hexadecimal occur in computer science; there are remnantsof a vigesimal system in French and the older Welsh system of counting; base60 was used by astronomers in ancient Mesopotamia and is still the basis oftime measurement (60 seconds = 1 minute, and 60 minutes = 1 hour) andangle measurement.

4.3.3 Decimal fractions

I shall describe in this section the decimal fractions which correspond torational numbers. This will give us some insight into the difference betweenrational and irrational numbers. To see what’s involved, let’s calculate somedecimal fractions.

Examples 4.3.3.

1. 120

= 0 · 05. This fraction has a finite decimal representation.

2. 17

= 0 · 142857142857142857142857142857 . . .. This fraction has aninfinite decimal representation, which consists of the same sequence ofnumbers repeated. We abbreviate this decimal to 0 · 142857.

3. 3784

= 0 · 44047619. This fraction has an infinite decimal representation,which consists of a non-repeating part followed by a part which repeats.

Case (2) is said to be a purely periodic decimal whereas case (3), whichis more general, is said to be ultimately periodic.

Proposition 4.3.4. A proper rational number ab

in its lowest terms has afinite decimal expansion if and only if b = 2m5n for some natural numbers mand n.

Page 26: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

106 CHAPTER 4. NUMBER THEORY

Proof. Let ab

have the finite decimal representation 0 · a1 . . . an. This means

a

b=a1

10+

a2

102+ . . .+

an10n

.

The righthand side is just the fraction

a110n−1 + a210n−2 + . . .+ an10n

.

The denominator contains only the prime factors 2 and 5 and so the reducedform will also only contain at most the prime factors 2 and 5.

To prove the converse, consider the proper fraction

a

2α5β.

If α = β then the denominator is 10α. If α 6= β then multiply the fraction bya suitable power of 2 or 5 as appropriate so that the resulting fraction hasdenominator a power of 10. But any fraction with denominator a power of10 has a finite decimal expansion.

Proposition 4.3.5. An infinite decimal fraction represents a rational num-ber if and only if it is ultimately periodic.

Proof. Consider the ultimately periodic decimal number

r = 0 · a1 . . . asb1 . . . bt.

We shall prove that r is rational. Observe that

10sr = a1 . . . as · b1 . . . bt

and10s+t = a1 . . . asb1 . . . bt · b1 . . . bt.

From which we get that

10s+tr − 10sr = a1 . . . asb1 . . . bt − a1 . . . as

where the righthand side is the decimal form of some integer that we shallcall a. It follows that

r =a

10s+t − 10s

Page 27: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.3. WRITING NUMBERS DOWN 107

is a rational number.The proof of the converse is based on the method we use to compute

the decimal expansion of mn

. We carry out repeated divisions by n and ateach step of the computation we use the remainder obtained to calculatethe next digit. But there are only a finite number of possible remaindersand our expansion is assumed infinite. Thus at some point there must berepetition.

Example 4.3.6. We shall write the ultimately periodic decimal 0 · 94. as aproper fraction in its lowest terms. Put r = 0 · 94. Then

• r = 0 · 94.

• 10r = 9.444 . . .

• 100r = 94.444 . . ..

Thus 100r−10r = 94−9 = 85 and so r = 8590

. We can simplify this to r = 1718

.We can now easily check that this is correct.

Exercises 4.3

1. Write the number 2009 in

(a) Base 5.

(b) Base 12.

(c) Base 16.

2. Write the following numbers in base 10.

(a) DAB16.

(b) ABBA12.

(c) 443322115.

3. For each of the following fractions determine whether they have finiteor infinite decimal representations. If they have infinite decimal rep-resentations determine whether they are purely periodic or ultimatelyperiodic; in both cases determine the periodic block.

Page 28: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

108 CHAPTER 4. NUMBER THEORY

(a) 12.

(b) 13.

(c) 14.

(d) 15.

(e) 16.

(f) 17.

4. Write the following decimals as fractions in their lowest terms.

(a) 0 · 534.

(b) 0 · 2106.

(c) 0 · 076923.

4.4 Numerical partial fractions

This section is intended as motivation for the partial fraction representationof rational functions described in a later chapter, so it can be omitted at firstreading. The idea is to show how a fraction can be written as a sum of otherfractions having a particular form. Specifically, the goal of this section is toshow how a proper fraction can be written as a sum of proper fractions overprime power denominators. This involves two steps which I shall describe bymeans of examples. The theory is an application of the fundamental theoremor arithmetic and the extended Euclidean algorithm.

In order to add two fractions together, we first have to ensure that bothare expressed over the same denominator. For example, suppose we want toadd 5

7and 8

13. Since 7× 13 = 91 we have the following

5

7+

8

13=

65 + 56

91=

121

91.

We shall now consider the reverse process, using the fraction 8101003

as anexample. Observe that 1003 = 17 × 59 where 17 and 59 are coprime. Ourgoal is to write

810

1003=

a

17+

b

59

Page 29: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.4. NUMERICAL PARTIAL FRACTIONS 109

for some natural numbers a and b. By the extended Euclidean algorithm, wecan write

1 = 7 · 17− 2 · 59.

It follows that1

1003=

7 · 17− 2 · 59

17 · 59=

7

59− 2

17.

Now multiply both sides by 810 to get

810

1003=

7 · 810

59− 2 · 810

17= 96

6

59− 95

5

17= 1 +

6

59− 5

17.

Simplifying we get810

1003=

6

59+

12

17

as required.We shall now do something different. Consider the fraction 10

16. We have

that 16 = 24 and so we cannot write it as a product of coprime numbers.However, we can do something else. We can write 10 = 2+8 = 21 +23. Thus

10

16=

21 + 23

24=

21

24+

23

24=

1

23+

1

2

and so10

16=

1

21+

1

23.

Let’s now combine these two steps. Consider the fraction 4190

. The primefactorisation of 90 is 2 · 32 · 5. Our first goal is to write

41

90=a

2+

b

32+c

5.

Thus we have to find a, b, c such that

41 = 45a+ 10b+ 18c.

By trial and error, remembering that a, b, c have to be integers, we find that

41 = 45 · 1 + 10 · 5 + (−3) · 18.

It follows that41

90=

1

2+

5

32− 3

5.

Page 30: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

110 CHAPTER 4. NUMBER THEORY

We now want to write5

32=d

3+

e

32

where |d| , |e| < 3. But 5 = 2 + 3 and so

5

32=

1

3+

2

32.

It follows that41

90=

1

2+

1

3+

2

9− 3

5.

We may summarise what we have found in the following theorem.

Theorem 4.4.1.

(i) Let ab

be a proper fraction, and let b = pn11 . . . pnr

r be the prime factorisationof b. Then

a

b=

r∑

i=1

cipnii

for some integers ci, where each of the fractions is proper.

(ii) Now let p be a prime and cpn

a proper fraction. Then

c

pn=

n∑

j=1

djpj

where each dj is such that |dj| < p.

4.5 Modular arithmetic

From an early age, we are taught to think of numbers as being strung outalong the number line

0 1 2 3−1−2−3

But that is not the only way we count. We count the seasons in a cyclicmanner

. . . autumn, winter, spring, summer . . .

Page 31: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.5. MODULAR ARITHMETIC 111

and likewise the days of the week

. . . Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday . . .

Also the months of the year or the hours in a day, whether by means of the 12-hour clock or the 24-hour clock. The fact that we use words for these eventsobscures the fact that we really are counting. This is clearer in the namesfor the months since October, November and December were originally theeighth, ninth and tenth months, respectively, until Roman politics intervenedand they were shifted. But the counting in all these cases is not linear butcyclic. Rather than using a number line to represent this type of counting,we use instead number circles, and rather than using the words above, Ishall use numbers. Here is the number circle for the seasons with numbersreplacing words.

0

1

2

3

Adding in these systems of arithmetic means stepping around in a clockwisedirection, whereas subtracting means stepping around in an anticlockwisedirection. Modular arithmetic is the name given to these different systemsof cyclic counting. It was Gauss who realised that these different systems ofcounting were mathematically interesting.

4.5.1 Congruences

Let n ≥ 2 be a fixed natural number which in this context we call themodulus. If a, b ∈ Z we write a ≡ b if, and only if, a and b leave the sameremainder when divided by n or, what amounts to the same thing, n | a− b.

Here are a couple of simple examples. If n = 2, then a ≡ b if, and onlyif, a and b are either both odd or both even. On the other hand, if n = 10then a ≡ b if, and only if, a and b have the same units digit.

Page 32: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

112 CHAPTER 4. NUMBER THEORY

The symbol ≡ is a modification of the equality symbol =. If a ≡ b withrespect to n we say that a is congruent to b modulo n. In fact, congruencebehaves like a weakened form of equality as we now show.

Lemma 4.5.1. Let n ≥ 2 be a fixed modulus.

1. a ≡ a.

2. a ≡ b implies b ≡ a.

3. a ≡ b and b ≡ c implies that a ≡ c.

4. a ≡ b and c ≡ d implies that a+ c ≡ b+ d.

5. a ≡ b and c ≡ d implies that ac ≡ bd.

Here is a very simple application of modular arithmetic.

Lemma 4.5.2. A natural number n is divisible by 9 if, and only if, the sumof the digits of n is divisible by 9.

Proof. We shall work modulo 9. The proof hinges on the fact that 10 ≡ 1modulo 9. By using Lemma 4.5.1, we quickly find that 10r ≡ 1 for all naturalnumbers r ≥ 1. We use this result now. Let

n = an10n + an−110n−1 + . . .+ a110 + a0.

Then n ≡ an+ . . .+a0. Thus n and the sum of the digits of n leave the sameremainder when divided by 9, and so n is divisible by 9 if, and only if, thesum of the digits of n are divisible by 9.

Solving a linear equation such as ax+by = c is very easy. For each possiblereal value of x we can compute the corresponding real value of y. But supposenow that a, b and c are integers and we only want to find solutions (x, y) whoseco-ordinates are integers? This is an example of a Diophantine equation. Weshall show how it may solved with the help of modular arithmetic. First,we shall show that the problem of finding integer solutions is equivalent tosolving a simple kind of liner equation in one unknown in modular arithmetic.

Lemma 4.5.3. Let a, b and c be integers. Then the following are equivalent.

1. The pair (x1, y1) is an integer solution to ax+ by = c for some y1.

Page 33: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.5. MODULAR ARITHMETIC 113

2. The integer x1 is a solution to the equation ax ≡ c (mod b).

Proof. (1) ⇒ (2). Suppose that ax1 + by1 = c. Then it is immediate thatax1 ≡ c (mod b).

(2) ⇒ (1). Suppose that ax1 ≡ c (mod b). Then by definition, ax1− c =bz1 for some integer z1. Thus ax1 + b(−z1) = c. We may therefore puty1 = z1.

We shall now describe how to solve all equations of the form

ax ≡ b (mod n).

Lemma 4.5.4. Consider the linear congruence ax ≡ b (mod n).

1. The linear congruence has a solution if, and only if, d = gcd(a, n) issuch that d | b.

2. If the condition in part (1) holds and x0 is any solution, then all solu-tions have the form

x = x0 + tn

d

where t ∈ Z.

Proof. (1). Suppose first that x1 is a solution to our linear congruence. Thenby definition, ax1−b = nq for some integer q. It follows that ax1+n(−q) = b.By definition d | a and d | n and so d | b.

We now prove the converse. By Bezout’s theorem, we may find integersu and v such that au+nv = d. By assumption, d | b and so b = dw for someinteger w. It follows that auw + nvw = dw = b. Thus a(uw) ≡ b (mod n),and we have found a solution.

(2) Let x0 be any one solution to ax ≡ b (mod n). It is routine to checkthat x = x0 + tn

dfor any t ∈ Z. Let x1 be any solution to ax ≡ b (mod n).

Then a(x1− x0) ≡ 0 (mod n). Thus a(x1− x0) = tn for some integer t. Theresult now follows.

There is a special case of the above result that is very important. Itsproof is immediate.

Corollary 4.5.5. Let p be a prime. Then the linear congruence ax ≡ b(mod p), where a is not congruent to 0 modulo p, always has a solution, andall solutions are congruent modulo p.

Page 34: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

114 CHAPTER 4. NUMBER THEORY

Example 4.5.6. Let’s find all the points on the line 2x + 3y = 5 that haveinteger co-ordinates. Observe first that gcd(2, 3) = 1. Thus such points exist.In this case, by inspection, 1 = 2 · 2 + (−1)3. Thus 5 = 10 · 2 + (−5)3. Itfollows that (10,−5) is one point on the line with integer co-ordinates. Thusthe set of integer solutions is

{(10 + 3t,−5− 2t) : t ∈ Z}.

4.5.2 Wilson’s theorem

I shall finish off this section with an application of congruences to primes.It is the first hint of hidden patterns in the primes. We need some notationfirst. For each natural number n define n!, pronounced n factorial, or ifyou are more extrovert n shriek, as follows: 0! = 1 and for n > 0 definen! = n · (n − 1)!. In other words, n! is what you get when you multiplytogether all the positive integers less than or equal to n. For each naturalnumber n, we shall be interested in the value of (n− 1)! modulo n. Observethat there is no point in studying n! (mod n) since the answer is always 0.It’s worth doing some numerical calculations first to see if you can spot apattern.

Theorem 4.5.7 (Wilson’s Theorem). Let n be a natural number. Then n isa prime if, and only if,

(n− 1)! ≡ n− 1 (mod n)

Since n− 1 ≡ −1 (mod n) this is usually expressed in the form

(n− 1)! ≡ −1 (mod n).

Proof. The statement to be proved is an ‘if, and only if’ and so we have toprove two statements: (1) If n is prime then (n − 1)! ≡ n − 1 (mod n). (2)If (n− 1)! ≡ n− 1 (mod n) then n is prime.

We prove (1) first. Let n be a prime. The result is clearly true whenn = 2 so we may assume n is an odd prime. For each 1 ≤ a ≤ n − 1 thereis a unique number 1 ≤ b ≤ n − 1 such that ab ≡ 1 (mod n). If a = b thena1 ≡ 1 (mod n) which means that n | (a − 1)(a + 1). Since n is a primeeither n | a− 1 or a | a+ 1. This can only occur if a = 1 or a = n− 1. Thus(n− 1)! ≡ n− 1 (mod n), as claimed.

Page 35: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 115

We now prove (2). Suppose that (n−1)! ≡ n−1 (mod n). We prove thatn is a prime. Observe that when n = 1 we have that (n − 1)! = 1 which isnot congruent to 0 modulo 1. When n = 4, we get that (4−1)! ≡ 2 (mod 4).Suppose that n > 4 is not prime. Then n = ab where 1 < a, b < n. If a 6= bthen ab occurs as a factor of (n− 1)! and so this is congruent to 0 modulo n.If a = b then a occurs in (n− 1)! and so does 2a. Thus n is again a factor of(n− 1)!.

This theorem is interesting for another reason. To show that a numberis prime, we would usually apply the algorithm we described earlier whichis just a systematic way of carrying out trial division. This theorem showsthat a number is prime in a completely different way. Although it is not apratical test for deciding whether a number is prime or composite, since n!gets very big very quickly, it shows that there might be backdoor ways ofshowing that a number is prime. This is a very important question in thelight of the role of prime numbers in cryptography.

4.6 Continued fractions

The goal of this section is to show how some of the ideas we have introducedso far can interact with each other. The material we cover is not neededelsewhere in this book.

4.6.1 Fractions of fractions

We return to an earlier calculation. We used Euclid’s algorithm to calculategcd(19, 7) as follows.

19 = 7 · 2 + 5

7 = 5 · 1 + 2

5 = 2 · 2 + 1

2 = 1 · 2 + 0

Page 36: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

116 CHAPTER 4. NUMBER THEORY

We first rewrite each line, except the last, as follows

19

7= 2 +

5

27

5= 1 +

2

55

2= 2 +

1

2

Take the first equality19

7= 2 +

5

2.

But 57

is the reciprocal of 75, and from the second equality

7

5= 1 +

2

5.

If we combine them, we get

19

7= 2 +

1

1 + 25

however strange this may look. We may repeat the process to get

19

7= 2 +

1

1 +1

2 + 12

Fractions like this are called continued fractions. Suppose I just gave you

2 +1

1 +1

2 + 12

You could work out what the usual rational expression was by working fromthe bottom up. First compute the part in bold below

2 +1

1 +1

2 + 12

Page 37: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 117

to get

2 +1

1 +152

which simplifies to

2 +1

1 + 25

This process can no be repeated and we shall eventually obtain a standardfraction.

I am not going to develop the theory of continued fractions, but I shallshow you one more application. Let r be a real number. We may writer as r = m1 + r1 where 0 ≤ r1 < 1. For example, π may be written asπ = 3 · 14159265358 . . . where here m = 3 and r1 = 0 · 14159265358 . . .. Nowsince r1 < 1 and assume that it is non-zero. Then 1

r1> 1. We may therefore

repeat the above process and write 1r1

= m2 + r2 where once again r2 < 1.This begin to feel an aweful lot like what we did above. In fact, we may write

r = m1 +1

m2 + r2

,

and we can continue the above process with r2. It looks like we would obtaina continued fraction representation of r with the big difference that it couldbe infinite. Here is a concrete example.

Example 4.6.1. We apply the above process to√

3. Clearly, 1 <√

3 < 2.Thus √

3 = 1 + (√

3− 1)

where√

3− 1 < 1. We now focus on

1√3− 1

.

To convert this into a more usable form we multiple top and bottom by√3 + 1. We therefore get that

1√3− 1

=1

2(√

3 + 1).

Page 38: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

118 CHAPTER 4. NUMBER THEORY

It is clear that 1 < 12(√

3 + 1) < 112. Thus

1√3− 1

= 1 +

√3− 1

2.

We now focus on2√

3− 1

which simplifies to√

3 + 1. Clearly

2 <√

3 + 1 < 3.

Thus√

3 + 1 = 2 + (√

3 − 1). However, we have now gone full circle. Let’ssee what we have obtained. We have that

√3 = 1 +

1

1 +1

2 + (√

3− 1)

.

However, we saw above that the pattern repeats as√

3 − 1, so what weactually have is

√3 = 1 +

1

1 +1

2 +1

1 +1

. . .

.

Let’s see where we are by computing

1 +1

1 +1

2 +1

1

which simplifies to 74. You can check that this is an approximation to

√3.

Page 39: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 119

4.6.2 Rabbits and pentagons

We now illustrate some of the ways that algebra and geometry may inter-act. We begin with an artificial looking question. In his book, Liber Abaci,Fibonacci raised the following little puzzle which I’ve taken from MacTutor:

“A certain man put a pair of rabbits in a place surrounded onall sides by a wall. How many pairs of rabbits can be producedfrom that pair in a year if it is supposed that every month eachpair begets a new pair which from the second month on becomesproductive?”

These are obviously mathematical rabbits rather than real ones so let mespell out the rules more explicitly:

Rule 1 The problem begins with one pair of immature rabbits.2

Rule 2 Each immature pair of rabbits takes one month to mature.

Rule 3 Each mature pair of rabbits produces a new immature pair at theend of a month.

Rule 4 The rabbits are immortal.

The important point is that we must solve the problem using the rules wehave been given. To do this, I am going to draw a picture. I will representan immature pair of rabbits by ◦ and a mature pair by •. Rule 2 will berepresented by

��•and Rule 3 will be represented by

��~~~~~~~

��@@@@@@@

• ◦Rule 1 tells us that we start with ◦. Applying the rules we obtain the followingpicture for the first 4 months.

2Fibonacci himself seems to have assumed that the starting pair was already maturebut we shan’t.

Page 40: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

120 CHAPTER 4. NUMBER THEORY

��

1 pair

����������

��<<<<<<<< 1 pair

����������

��<<<<<<<< ◦

��<<<<<<<< 2 pairs

����������

��<<<<<<<< ◦

��

����������

��<<<<<<<< 3 pairs

• ◦ • • ◦ 5 pairs

We start with 1 pair and at the end of the first month we still have 1 pair, atthe end of the second month 2 pairs, at the end of the third month 3 pairs,and at the end of the fourth month 5 pairs. I shall write this F0 = 1, F1 = 1,F2 = 2, F3 = 3, F4 = 5, and so on. Thus the problem will be solved if wecan compute F12. There is an apparent pattern in the sequence of numbers1, 1, 2, 3, 5, . . . after the first two terms in the sequence each number is thesum of the previous two. Let’s check that we are not just seeing things.Suppose that the number of immature pairs of rabbits at a given time t isIt and the number of mature pairs is Mt. Then using our rules at time t+ 1we have that Mt+1 = Mt + It and It+1 = Mt. Thus

Ft+1 = 2Mt + It.

SimilarlyFt+2 = 3Mt + 2It.

It is now easy to check that

Ft+2 = Ft+1 + Ft.

The sequence of numbers such that F0 = 1, F1 = 1 and satisfying therule Ft+2 = Ft+1 + Ft is called the Fibonacci sequence. We have that

F0 = 1, F1 = 1, F2 = 2, F3 = 3, F4 = 5, F5 = 8, F6 = 13, F7 = 21,

F8 = 34, F9 = 55, F10 = 89, F11 = 144, F12 = 233.

Page 41: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 121

The solution to the original question is therefore 233 pairs of rabbits.Fibonacci numbers arise in the most diverse situations: famously, in phyl-

lotaxis which is the study of how leaves and petals are arranged on plants.We shall now look for a formula that will enable us to calculate Fn directly.To begin, we’ll follow an idea due to the astronomer Jonannes Kepler, andlook at the behaviour of the fractions Fn+1

Fnas n gets bigger and bigger. I

have tabulated some calculations below.

F1

F0

F2

F1

F3

F2

F4

F3

F5

F4

F6

F5

F7

F6

F14

F13

1 2 1 · 5 1 · 6 1 · 625 1 · 615 1 · 619 1 · 6180

These ratios seem to be going somewhere; the question is: where? Noticethat

Fn+1

Fn=Fn + Fn−1

Fn= 1 +

Fn−1

Fn= 1 +

1Fn

Fn−1

.

But for very large n we suspect that Fn+1

Fnand Fn

Fn−1will be almost the same.

This suggests, but doesn’t prove, that we need to find the positive solutionx to

x = 1 +1

x.

Thus x is a number that when you take its reciprocal and add 1 you get xback again. This problem is really a quadratic equation in disguise

x2 = x+ 1 or more usually x2 − x− 1 = 0.

This equation can be solved very simply to give us

x =1±√

5

2.

That is

φ =1 +√

5

2and φ =

1−√

5

2.

The number φ is called the golden ratio, about which a deal of nonsense hasbeen written. Let’s go back and see if this calculation makes sense. First wecalculate φ and we get

φ = 1 · 618033988 . . .

I computeF19

F18

=6765

4181= 1 · 618033963

Page 42: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

122 CHAPTER 4. NUMBER THEORY

on my pocket calculator. This is pretty close.We can now get our formula for the Fibonacci numbers. Define

fn =1√5

(φn+1 − φn+1

).

I’m going to show you that Fn = fn. To do this, I’ll use the followingidentities which are straightforward to check

φ− φ =√

5 φ2 = φ+ 1 and φ2 = φ+ 1.

Let’s start with f0. We know that

φ− φ =√

5

and so we really do have that f0 = 1. To calculate f1 we use the otherformulae and again we get f1 = 1. We now calculate fn + fn+1 we get

fn + fn+1 =1√5

(φn+1 − φn+1

)+

1√5

(φn+2 − φn+2

)

=1√5

(φn+1 + φn+2 − (φn+1 + φn+2)

)

=1√5

(φn+1(1 + φ)− φn+1(1 + φ)

)

=1√5

(φn+1φ2 − φn+1φ2

)

=1√5

(φn+3 − φn+3

)= fn+2

Because fn and Fn start in the same place and satisfy the same rules, wehave therefore proved that

Fn = 1√5

(φn+1 − φn+1

).

At this point, we can go back and verify our original idea that the fractionsFn+1

Fnseem to get closer and closer to φ as n gets larger and larger. We have

that

Fn+1

Fn=

φn+2 − φn+2

φn+1 − φn+1

1− ( φφ)n+1

− 11φ(φφ)n+1 − 1

φ

Page 43: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 123

I have rewritten it like this so that we can see what happens as n gets largerand larger. Observe that the absolute value of φ

φis less than 1. So as n gets

larger and larger the first term above gets closer and closer to φ. Now lookat the second term. The absolute value of the fraction φ

φis strictly greater

than 1. Thus as n gets larger and larger the denominator of the second termgets larger and larger and so the fraction as a whole gets smaller and smaller.Thus we have proved that Fn+1

Fnreally is close to φ when n is large.

So far, what we have been doing is algebra. I shall now show that thereis geometry here as well. Below is a picture of a regular pentagon. I haveassumed that the length of the sides is 1. I claim that the length of a diagonal,such as BE, is equal to φ.

A

E

B

C

D

φ

1

To prove this I am going to use Ptolomy’s theorem. We shall concentrate onthe cyclic quadrilateral formed by the vertices ABDE.

A

B

C

D

E

I’ll let the side of a diagonal be x. Then by Ptolomy’s theorem, we have that

x2 = 1 + x.

Page 44: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

124 CHAPTER 4. NUMBER THEORY

But this is precisely the quadratic equation we solved above. Its positivesolution is φ and so the length of a diagonal of a regular pentagon with side1 is φ.

This raises the question of whether we can somehow see the Fibonaccinumbers in the regular pentagon. The answer is: almost. Consider thediagram below.

A

B

C

D

E

a′

e′d′

b′c′

I’ve drawn in all the diagonals. The shaded triangle BCD is similar to theshaded triangle Ac′E. This means that they have exactly the same shapesjust different sizes. It follows that

Ac′

AE=BC

BD.

But AE is a side of the pentagon and so has unit length, and BD is of lengthφ. Thus

AC ′ =1

φ.

Now, Dc′ has the same length as BC which is a side of the pentagon. ThusDc′ = 1. We now have

φ = DA = Dc′ + c′A = 1 +1

φ.

Thus, just from geometry, we get

φ = 1 +1

φ.

Page 45: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

4.6. CONTINUED FRACTIONS 125

This is a very odd equation because φ is mentioned on both sides. Let’s gowith it and repeat:

φ = 1 +1

1 + 1φ

and

φ = 1 +1

1 +1

1 + 1φ

and

φ = 1 +1

1 +1

1 +1

1 + 1φ

and so on. We therefore obtain a continued fraction. For each of thesefractions cover up the term 1

φand then calculate what you see to get

1, 1 +1

1= 2, 1 +

1

1 + 11

=3

2, 1 +

1

1 +1

1 + 11

=5

3, . . .

and the Fibonacci sequence reappears.

Page 46: Chapter 4 Number theory - h markl/teaching/ALGEBRA/Chapter4new.pdf · the primes are the building blocks, or atoms, from which all integers are constructed. The primes are still the

126 CHAPTER 4. NUMBER THEORY