Introduction to Number Theory With Computing [1 ed.] 0713136618, 9780713136616

This introduction to number theory has been written specifically for mathematics and computing undergraduates. Computer

116 30

English Pages x, 309 [328] Year 1989

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Introduction to Number Theory With Computing [1 ed.]
 0713136618, 9780713136616

  • Commentary
  • Archive.org (low res version) https://archive.org/details/introductiontonu0000alle | Published: 08 November 1989

Table of contents :
Preface v

0 Introduction 1
0.1 Fascinating numbers 1
0.2 Well ordering 5
0.3 The division algorithm 7
0.4 Mathematical induction 10
0.5 The Fibonacci sequence 12
Portrait and biography of Fibonacci 12
0.6 A method of proof (reductio ad absurdum) 15
0.7 A method of disproof (the counterexample) 16
0.8 Iff 18

1 Divisibility 19
1.1 Primes and composites 19
1.2 The sieve of Eratosthenes 22
1.3 The infinitude of primes 25
1.4 The fundamental theorem of arithmetic 29
Portrait and biography of Hilbert 32
1.5 GCDs and LCMs 34
1.6 The Euclidean algorithm 37
1.7 Computing GCDs 40
1.8 Factorisation revisited 43

2 More About Primes—A Historical Diversion 47
2.1 A false dawn and two sorry tales 47
Portrait and biography of Dickson 50
2.2 Formulae generating primes 51
Portrait and biography of Dirichlet 53
2.3 Prime pairs and Goldbach’s conjecture 56
2.4 A wider view of the primes. The prime number theorem 58
2.5 Bertrand’s conjecture 67
Biography of Mersenne 70
2.6 Mersenne’s and Fermat’s primes 70

3 Congruences 75
3.1 Basic properties 75
3.2 Fermat’s little theorem 82
Portrait and biography of Fermat 83
3.3 Euler’s function 88
3.4 Euler’s theorem 95
3.5 Wilson’s theorem 97

4 Congruences Involving Unknowns 102
4.1 Linear congruences 102
4.2 Congruences of higher degree 109
4.3 Quadratic congruences modulo a prime 115
Portrait and biography of Lagrange 117
4.4 Lagrange’s theorem 118

5 Primitive Roots 123
5.1 A converse for the FLT 123
5.2 Primitive roots of primes. Order of an element 125
Biography of Legendre 126
5.3 Gauss’s theorem 132
5.4 Some simple primality tests. Pseudoprimes. Carmichael numbers 136
5.5 Special repeating decimals 142

6 Diophantine Equations and Fermat’s Last Theorem 146
6.1 Introduction 146
6.2 Pythagorean triples 148
6.3 Fermat’s last theorem 153
6.4 History of the FC 155
Portrait and biography of Germain 158
6.5 Sophie Germain’s theorem 159
6.6 Cadenza 161

7 Sums of Squares 163
7.1 Sums of two squares 163
Portrait and biography of Mordell 166
7.2 Sums of more than two squares 169
7.3 Diverging developments and a little history 174

8 Quadratic Reciprocity 179
8.1 Introduction 179
8.2 The law of quadratic reciprocity 179
Portrait and biography of Euler 180
8.3 Euler’s criterion 185
8.4 Gauss’s lemma and applications 188
8.5 Proof of the LQR—more applications 193
Portrait and biography of Jacobi 197
8.6 The Jacobi symbol 198
8.7 Programming points 200

9 The Gaussian Integers 202
9.1 Introduction 202
Portrait and biography of Gauss 203
9.2 Divisibility in the Gaussian integers 205
9.3 Computer manipulation of Gaussian integers 209
9.4 The fundamental theorem 212
9.5 Generalisation. Two problems of Fermat 214
9.6 Lucas’s test 221

10 Arithmetic Functions 224
10.1 Introduction 224
10.2 Multiplicative arithmetic functions 229
Portrait and biography of Mobius 235
10.3 The Mdbius function 235
10.4 Averaging—a smoothing process 240

11 Continued Fractions and Pell’s Equation 249
11.1 Finite continued fractions 249
11.2 Infinite continued fractions 252
11.3 Computing continued fractions for irrational numbers 258
11.4 Approximating irrational numbers 261
11.5 iscfs for square roots and other quadratic irrationals 264
Biography of Pell 267
11.6 Pell’s Equation 267
11.7 Two more applications 272

12 Sending Secret Messages 277
12.1 A cautionary tale 277
12.2 The Remedy: the RSA cipher system 279

Appendices I Multiprecision arithmetic 285
II Table of least prime factors of integers 293

Bibliography 299

Index 303

Index of Notation 310

Citation preview

R B J T ALLENBY AND EJREDFERN /

_

th

NUNC COGNOSCO EX PARTE

THOMASJ. BATA LIBRARY TRENT UNIVERSITY

f Digitized by the Internet Archive in 2019 with funding from Kahle/Austin Foundation

https://archive.org/details/introductiontonuOOOOalle

r

I

(

Introduction to Number Theory with Computing R B J T Allenby and E J Redfern School of Mathematics, University of Leeds

Edward Arnold A division of Hodder & Stoughton LONDON MELBOURNE AUCKLAND

© 1989 R B J T Allenby and E J Redfern First published in Great Britain 1989 Distributed in the USA by Routledge, Chapman and Hall, Inc. 29 West 35th Street, New York, NY 10001 British Library Cataloguing in Publication Data

Allenby, R.B.J.T. Introduction to number theory with computing 1. Number theory I. Title II. Redfern, E.J. 512'.7 ISBN 0-7131-3661-8 All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronically or mechanically, including photocopying, recording or any information storage or retrieval system, without either prior permission in writing from the publisher or a licence permitting restricted copying. In the United Kingdom such licences are issued by the Copyright Licensing Agency: 33-34 Alfred Place, London WC1E 7DP Typeset in 10/12 pt Times by J W Arrowsmith Ltd, Bristol. Printed and bound in Great Britain for Edward Arnold, the educational, academic and medical publishing division of Hodder and Stoughton Limited, 41 Bedford Square, London WC1B 3DQ by J W Arrowsmith Ltd, Bristol

Preface I have always thought of number theory as an experimental science and, even before the days of computers. Gauss and Ramanujan and others often treated it this way Prof. Richard K Guy, in a letter, 86-09-10

As its title is meant to indicate, this book is first and foremost a book about number theory, in particular about those aspects of (elementary) number theory frequently to be found in 'first courses’ in universities and other centres of higher education. Indeed the first author, on writing to several mathematics departments both in the UK and abroad, discovered a remarkable unanimity in what is regarded as being appropriate for such a course. A glance at the Contents will reveal what many of these items are. (In particular, one obvious candidate for a follow-up course, a proof of the prime number theorem, is not to be found here.) Our title was deliberately chosen so as to avoid giving the impression that this is an introduction to number theory and to computing. In fact one of our aims was to produce a text which could be used in two ways—both with the computing element and also without it. Thus, if the reader wishes, any use of the computer may be eschewed. On the other hand we certainly wished to show such a reader how the number-theoretic horizon can open up if the computer is admitted as an aid to calculation. There are many examples of this in the text. Sometimes the computer exhibits a counterexample to a plausible conjecture and thereby saves many hours of calculation by hand or—even better—much aggravation in attempting to prove something which is false. On the other side of the coin, the massive amount of information which a computer can process quickly can, not infrequently, show up an underlying pattern which might otherwise, for paucity of examples, go unnoticed. Indeed, if the evidence seems convincing, proofs can be attempted with, possibly, a little more confidence. If nothing else, the computational power of the computer allows those of us of more modest ability—such as the two authors—to rub shoulders with geniuses of the past such as Euler and Gauss by allowing us easy access to the kind of empirical evidence which they had to accumulate by hand. (Interestingly enough, Dickson’s amazing tome [1] on the history of the theory of numbers frequently describes those people whose (mainly pre-1900) work is being cited as ‘computers’!) Our title also carries with it the implication that, unlike the number-theoretic content, the computing element of this text does not begin entirely from scratch. Nevertheless many of the programs included in the book are pretty straightfor¬ ward; in any case we assume that the reader will have no difficulty in entering them into his computer. It is then our hope that those with no previous programming experience will be sufficiently captivated to produce programs of their own—beginning, perhaps, with simple modifications of ours.

iv

Preface

Those with a fair amount of programming experience will probably find little new from a programming point of view; our hope for them is that they be sufficiently enthralled by the number theory contained herein to direct their talents to making further discoveries of empirical relationships or counter¬ examples, as indicated above. (If further motivation is needed, note the stories concerning the 16-year-old Niccolo Paganini (Exercises 2.6) and the efforts of the 18-year-olds Laura Nickel and Curt Noll in Section 2.6.) If there were a reader at whom the computing aspect of this book is chiefly aimed it would be one—and this would include many still at school—who is familiar with the rudiments of programming but has not so far found a subject of sufficient interest to which to apply it. For such people an excursion into number theory as presented here is just the ticket! Of course, one of the most attractive features of the number theory presented in several of the chapters of this book is that, since the prerequisites are fairly few, almost everyone can join in the fun straight away. Nor is the computational side without its fascinating aspects. Apart from the problem of programming the computer so that it does what you want it to do, there is the interesting problem of constructing programs so that they run more efficiently. (Programs in this book are not always written with this efficiency in mind. Accordingly, you are left to try and improve any which take your fancy.) Of course one should try to avoid the attitude that every tedious task should be thrown at the computer without further ado. Whilst no attempt has been made to give a systematic account of the history of number theory, the authors have tried to give the reader at least a feeling for the continuing development of the subject by mentioning names and ascribing dates where it seems to be of interest. In addition, potted biographies and portraits of some of the leading figures in this development are included. There are, of course, many books already in print which deal with the subject matter discussed here, though many do not give much consideration to comput¬ ing. A very readable book in this category, which is at the same level as this text, is that by Burton [2], On the other hand, one which encourages use of the computer to introduce and consolidate number-theoretic ideas is Malm [3]. To learn about various (often unexpected) applications of the theory to the ‘real’ world one should consult [4] whilst a collection of fascinating open problems in pure number theory can be found in Guy’s book [5]. For the history of the theory of numbers Dickson’s ‘History’, referred to above, has to be delved into to be believed; if your interest in number theory is more modern, being aroused by the computing aspect, then Knuth’s book [6], Volume II, is a must. References to other books and articles, many of which make for an enjoyable read, are to be found in the Bibliography. A very brief word about the exercises, (computer) problems and programs. Appearing at the end of nearly every section, it is intended that the exercises be done without the aid of a computer. Naturally enough, the computer problems are (we hope) not all do-able by hand! The programs are presented in as near as possible a standard BASIC, the objective being to make them

Preface

v

widely available. They have all been tested on a BBC microcomputer and should all run in a finite amount of time! As is usual with a book of this kind, the authors find themselves wishing to thank a number of colleagues whose comments on the text have proved useful. In particular we should mention John McConnell and Bob Hart. However, our main thanks here go to the first author's research student, Lis Green, who, having chosen to attend the undergraduate course on which much of this book is based, volunteered to read the manuscript as a source of pleasure! The authors are also very much indebted to Prof. Dr Konrad Jacobs of the LIniversity of Erlangen-Niirnberg for supplying most of the photographs, to Alan Whittle, whose incredibly close attention to detail saved us from a number of embarrassments and to one of our undergraduates, Richard Warren, for a most timely remark. On reading through this book you might make the (correct) inference that the greater part of the text was written by one of the authors whilst the majority of the programs are from the pen (or, rather, the computer) of the other. As each author is assuming that what is written in his section has, at least, the approval of the other, each author happily blames his co-author for any remaining transgressions! Perhaps the reader will be good enough to inform the offending author of any mistakes, discrepancies, oversights etc. which occur in his ‘section’ of the book. On the other hand both authors hope that the reader will get as much pleasure from consulting this book as they had in composing it. Have fun! R B J T Allenby and E J Redfern 1988

Contents

0

Preface

v

Introduction

1

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8

1

1 5 7 10 12 12 15 16 18

Divisibility

19

1.1 1.2 1.3 1.4

19 22 25 29 32 34 37 40 43

1.5 1.6 1.7 1.8

2

Fascinating numbers Well ordering The division algorithm Mathematical induction The Fibonacci sequence Portrait and biography of Fibonacci A method of proof (reductio ad absurdum) A method of disproof (the counterexample) Iff

Primes and composites The sieve of Eratosthenes The infinitude of primes The fundamental theorem of arithmetic Portrait and biography of Hilbert GCDs and LCMs The Euclidean algorithm Computing GCDs Factorisation revisited

More About Primes—A Historical Diversion

47

2.1

47 50

2.2 2.3 2.4 2.5 2.6

A false dawn and two sorry tales Portrait and biography of Dickson Formulae generating primes Portrait and biography of Dirichlet Prime pairs and Goldbach’s conjecture A wider view of the primes. The prime number theorem Bertrand’s conjecture Biography of Mersenne Mersenne’s and Fermat’s primes

51

53 56 58 67

70 70

Contents

3

Congruences

75

3.1

Basic properties

75

3.2

Fermat’s little theorem Portrait and biography of Fermat Euler’s function Euler’s theorem Wilson’s theorem

82 83

3.3 3.4 3.5 4

Linear congruences Congruences of higher degree

109

4.3

Quadratic congruences modulo a prime Portrait and biography of Lagrange Lagrange’s theorem

102

115 117

118

Primitive Roots

123

5.1 5.2

123 125 126 132

A converse for the FLT Primitive roots of primes. Order of an element Biography of Legendre Gauss’s theorem Some simple primality tests. Pseudoprimes. Carmichael numbers Special repeating decimals

136 142

Diophantine Equations and Fermat’s Last Theorem

146

6.1 6.2 6.3 6.4

146 148 153 155 158 159 161

6.5 6.6

Introduction Pythagorean triples Fermat’s last theorem History of the FC Portrait and biography of Germain Sophie Germain’s theorem Cadenza

Sums of Squares

163

7.1

163 166 169 174

7.2 7.3

8

97

4.1 4.2

5.5

7

95

102

5.3 5.4

6

88

Congruences Involving Unknowns

4.4 5

vii

Sums of two squares Portrait and biography of Mordell Sums of more than two squares Diverging developments and a little history

Quadratic Reciprocity

179

8.1 8.2

Introduction The law of quadratic reciprocity

179 179

Portrait and biography of Euler

180

viii

9

Contents

8.3 8.4 8.5

Euler’s criterion Gauss’s lemma and applications Proof of the LQR—more applications Portrait and biography of Jacobi

185 188 193 197

8.6 8.7

The Jacobi symbol Programming points

198 200

The Gaussian Integers

202

9.1

202 203 205 209 212 214 221

9.2 9.3 9.4 9.5 9.6 10

11

12

Introduction Portrait and biography of Gauss Divisibility in the Gaussian integers Computer manipulation of Gaussian integers The fundamental theorem Generalisation. Two problems of Fermat Lucas’s test

Arithmetic Functions

224

10.1 Introduction 10.2 Multiplicative arithmetic functions Portrait and biography of Mobius 10.3 The Mdbius function 10.4 Averaging—a smoothing process

224 229 235 235 240

Continued Fractions and Pell’s Equation

249

11.1 11.2 11.3 11.4 11.5

Finite continued fractions Infinite continued fractions Computing continued fractions for irrational numbers Approximating irrational numbers iscfs for square roots and other quadratic irrationals Biography of Pell 11.6 Pell’s Equation 11.7 Two more applications

249 252 258 261 264 267 267 272

Sending Secret Messages

277

12.1 A cautionary tale 12.2 The Remedy: the RSA cipher system

277 279

Appendices I II

Multiprecision arithmetic Table of least prime factors of integers

285 293

Bibliography

299

Index

303

Index of Notation

310

Programs 0.1 0.2 0.3 0.4

To find all integers =£100 000 which are expressible in two distinct ways as the sum of two positive cubes To transform an integer into its separate digits (base 10) To check if a digital representation is palindromic To find integers that are not expressible as the sum of r integers each raised to the power v

Determines if an integer s=3 is prime or finds its smallest factor if it is composite 1.2 Generation of a list of primes using Eratosthenes’ Sieve 1.3 Modified Sieve of Eratosthenes program 1.4 To determine the prime factors of an integer N 1.5 Finds the prime factors and their exponents of an integer N 1.6 Calculation of gcd using the Euclidean algorithm 1.7 Calculation of gcd using only subtraction and division by two 1.8 Calculates gcd and expresses it as a linear combination of the two integers 1.9 Fermat’s method of factorising 1.10 Factorisation using only the operations of addition and subtraction (based on Fermat’s method)

3 8

9 16

1.1

2.1 2.2 2.3 2.4 3.1 3.2 3.3 3.4 4.1 4.2 4.3

Compact storage of prime lists Numerical integration using Simpson’s method Determines the number of primes up to N by the Fegendre formula To produce the decimal representations of Mersenne numbers Determination of b such that am = b(mod n). Determination of am(rnod n) To check possible factors (up to 232- 1) of Fermat or Mersenne numbers Determination of (n).

20 23 24 27 31 40 41 42 45 45 48 59 62 73 78 79 86

92

Computes the solutions (if any) to the linear congruence ax= b (mod m). To solve a system of simultaneous linear congruences Solves the quadratic congruence cur + bx + c = 0 (mod p)

104 106

where p is prime

116

x

5.1 5.2

6.1 6.2

7.1 7.2

Programs

Finds the primitive roots (if any) of any given integer N Finds the periodic decimal representation of 1/p working to base 10 To produce a list of primitive Pythagorean triples To produce primitive Pythagorean triples in increasing magnitude of the even side between values of / (lower) and u (upper)

129 143 150

151

Expresses a given integer N as the sum of two squares Finds all integers (less than some given integer N) that can be expressed as the sum of two squares

167

8.1 8.2

Calculation of the Legendre symbol using Gauss’s lemma Evaluation of the Jacobi Symbol

192 201

9.1 9.2 9.3

The division algorithm in Z[i] Computation of the GCD in Z [i] Computation in Z[i] of a linear combination expressing the GCD in terms of the original numbers Factorisation of a Gaussian integer by trial division The division algorithm in Z[Vd] Factorisation by trial division in Z[£].

209 210

9.4 9.5 9.6

167

210 211 219 219

10.1 Calculation of r(n) and cr(n)

226

11.1 Conversion of a rational number to continued fraction form 11.2 Conversion of a finite continued fraction to a rational number 11.3 Calculation of convergents given the successive terms n, in the

250 251

continued fraction [a0; ai, a2, ■ • •] 11.4 The continued fraction representation of any positive number 11.5 Continued fractions of quadratic irrationals 11.6 Factorisation using continued fractions

257 260 266 274

12.1 To encode a message using the RSA method 12.2 To decode a message using the RSA method

282 282

Al A2 A3 A4 A5 A6

285 286 286 287 288 289

Entry of long integers Display of long integers Multiprecision addition of the integers Multiprecision subtraction Multiprecision multiplication Multiprecision division

0 Introduction 0.1

Fascinating numbers

What is so fascinating about the positive integer* (i.e. whole number) 1729? The following story is told by the eminent British mathematician G. H. Hardyt in an obituary notice of the self-taught Indian genius Srinavasa Ramanujant. On visiting Ramanujan in hospital Hardy remarked that he had come in a taxi-cab whose licence number was 1729, a number he described as ‘rather dull’. Ramanujan who, it has been said, thought of each positive integer as a personal friend replied, ‘No, it is a very interesting number; it is the smallest number expressible as a sum of two [positive] cubes in two different ways’. The above story encourages us to ask the reader ‘Can you say anything interesting about the numbers* 30, 239, 341, 487, 945, 1093? If you work through this book you will find that you can! (And if you are still not convinced, you might care to find a flaw in the ‘proof’ (Exercise 0.2.3) that all positive integers are, in fact, fascinating!) Of course, if the study of numbers involved nothing more than answering questions of the above kind, our subject, at least at a serious level, would not have had amongst its devotees some of the world’s most powerful mathematicians. On the other hand, such numerological excursions are not wholly to be despised. Indeed an entire area of study of importance today, namely that concerning the Mersenne primes, arose out of philosophical speculations concerning numbers such as 6 ( = 1 +2 + 3) and 28 ( = 1 + 2 + 4 + 7+14) which are the sums of their proper divisors—that is, positive divisors other than the number itself (see Chapter 2). The numbers listed above are answers to just a few of the hoards of questions which arise quite naturally when an inquisitive person begins to look more closely at the integers, in particular the positive ones. Even if one restricts oneself to the prime numbers (see Definition 1.1.4) 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,... perfectly natural questions seem to pour forth in droves: (i)

Is each prime (from 3 on) less than twice its predecessor? (Or even less than I3 times it—from 13 onwards?)

* What is probably most fascinating about 1729 is that there is a fascinating story about it! Even without a calculator—but with some patience—anyone could discover its cubic properties. The properties which make some of the other numbers listed interesting are somewhat deeper, t Godfrey Harold Hardy, 7 February 1877 - 1 December 1947. $ Srinavasa Ramanujan, 22 December 1887 - 26 April 1920.

2

Introduction

(ii) (iii)

Can gaps, as large as we please, be found between successive primes? Are there infinitely many instances of pairs, such as 11, 13; 41, 43; 59, 61; ... of successive primes which differ by 2?

These questions illustrate one of the most attractive aspects of starting a study of the integers, that is, a study of the elementary theory of numbers. That aspect is the relative ease with which beginners can get a feeling of involvement in the subject by thinking up questions of the above types for themselves—and then trying to answer them! Indeed the writing of this book was partly stimulated by a young man from a local secondary school asking the first author the question: ‘Is it true that every odd integer 3=3 is either a prime or a sum of an odd prime and some power of 2?’ (No matter that the question had essentially been posed 135 years before; the young man’s delight in having found the problem for himself and in trying to answer it was obvious.) On the other hand, one of the most intriguing features of number theory is the difference in the degree of difficulty often encountered in trying to answer questions which are equally easy to pose. For example, of (i), (ii), (iii) above, the answer to one must have been known to Adam and Eve(!), another took some nine years to answer whilst the third is still unresolved. [Can you decide which of (i), (ii), (iii) these comments refer to?] One aim of this book is to introduce to you some of the undoubted delights that a study of the integers can provide even after only a relatively modest amount of preliminaries. We hope to get you involved in the subject, to encourage you to ‘get your hands dirty’ by experimenting for yourself, by making conjectures and then trying to verify (or disprove) them. To help in amassing evidence to support (or destroy) a conjecture and also to help see any ‘pattern’ which might be present—as the great mathematician C. F. Gauss (see p. 203) did before conjecturing the celebrated prime number theorem—the modern number theorist has the computer at his disposal. [Of course, getting the computer to confirm that a specific assertion is valid for all positive integers up to, say, 1025, by no means proves the assertion holds for all positive integers n (as computer problem 0.1.1 will emphasize). On the other hand, conjectures are disproved by finding counterexamples (see Section 0.7) and computers can be quite helpful in this regard. For instance, John Hill asserted (1727) that 139854276 ( = 11826") is the only perfect square which involves all nine non-zero digits once and once only. We leave the reader to construct a computer program to prove John Hill wrong. However, we take the opportunity to register, even in this simple case, a note of caution which may not only save time but can make all the difference between solving a problem or not. Think before you program. Failing to do so is quite likely to generate programs that take a longer time to run and also cover redundant cases. For example, to investigate John Hill’s claim we need only consider the squares of all the numbers between [vT23 456 789]* and [v/987 654 321], the smallest and largest candidates. [Of course, you also have * The notation [x] is used (mathematically) to indicate the greatest integer not exceeding x.

0.1 Fascinating numbers

3

to strike a balance between thinking time and the time you might expect your program to run. There is no point in thinking for a week to improve your program’s running time by a few seconds.] Likewise to confirm Moreau's assertion (1898) that there are precisely ten integers less than 100 000 which can be represented in more than one way as a sum of two positive cubes—and in particular to confirm Ramanujan’s remark that 1729 is the least—there is little point in asking your computer to check the equality x3 + y3 = z3+t3 for each x, y, z, t in the range 1 to VlOO 000. Indeed, for distinct representations one may clearly suppose that x is the smallest of the four integers so that y is the largest. That is, we write into the program the inequalities x+ by showing that the set of all positive rationals has no smallest member. Show that the set of all non-negative rationals does have a smallest member. Does the set of all rationals which are greater than V2 have a least member? Prove your assertion. 3 In [8] David Wells finds 39 to be the least uninteresting positive integer—so that, of course, it is very interesting indeed! This observation implies that if we apply the WO principle to the set, U say, of all (positive) uninteresting integers we find that U is the empty set. Consequently all integers are interest¬ ing—as is implicit in our earlier remarks!! Can this really be correct? Or is there a flaw in our proof? 4 Show that there is a least positive integer which is expressible in two distinct ways as the sum of two (positive or negative) cubes. (You are not asked to find it.)

Computer problem 0.2 1

Now find the integer mentioned in Exercise 0.2.4! Can you be sure you

have got the smallest?

0.3

The division algorithm

How fundamental WO is can be judged by showing its use in deriving the intuitively ‘obvious’ result known as The division algorithm (DA) Let a, be Z be such that 6 + 0. Then there exist unique integers m, re Z such that a — mb + r where 0 s£ r < |i>|. Consider the set D = {a + m\b\: meZ and a + m\b\^0}. Then D + 0, since on taking m = \a\ we find a + m\b\-a + ja| |6| 5* a + |u| s* 0. Now using the WO principle, D contains a smallest element r, say. Suppose r = a + m0\b\ 3= 0 where m0 e Z. Then r 0, we have a = (-m0)b + r: if 6 2, n! + 2, n! + 3, ...,n\+n constitutes a sequence of n -1 consecutive composites. Use this to find an example of 6 successive composites. Find the least positive integer k such that k, k + \,..., k + 5 are all composite. 2 Show that for 4, all integers from n\ — n to n\ + n inclusive with the possible exception of n\ — 1 and n! + l are composite. 3 Find positive integers n so that, of the integers n! — 1 and n!+l, (i) each is prime; (ii) each is composite, (iii) one is prime and one is composite. Find positive integers n so that, of the integers n\-n- 1 and n! + n + l, (i) each is prime; (ii) each is composite; (iii) one is prime and one is composite.

4

5

Why can no three successive odd numbers, except 3, 5, 7, all be primes?

Computer problems 1.2 1 Modify Program 1.2 to consider (i) only odd integers that are not multiples * of 3; (ii) to omit multiples of 5 as well.

1.3 The infinitude of primes

25

Compare the running time required by the programs to produce the primes up to N — 1000, 2000 and 3000 with those of the programs in the text and also with those of Problem 1.1.3. Extend the value of N as far as possible for each of the programs to obtain the maximum number of primes that your computer can find in each case. Write a program to determine the gaps between successive primes and to produce a table of the value of N at which the first gap of size x occurs. Using the modified sieve program with 32K of available memory you should be able to get as far as gaps of about 30. Are there likely to be gaps correspond¬ ing exactly to every even integer? 2

3 Modify Program 1.2 to produce a list of the primes between two given integers. Use your program to produce a list of the primes in each block of 1000 integers up to 100 000 recording the number of primes found in each block. Find the first occurrence of (i) 50; (ii) 100 consecutive composites. [Hint: You will need to modify Program 1.3 to allow consideration of successive ranges of integers.]

4

Lucky numbers (see [5]) are generated by the following sieving process. From the list of integers delete the even numbers. Apart from 1 the first remaining number is 3. Strike every third member of those remaining. The next number remaining is 7 so we strike out every 7th term in the remaining sequence. Continuing in this way we are left with a set of numbers called the lucky numbers. Write a program to perform such a sieving process to generate the lucky numbers. 5

6 Write a program to compare the nth Fibonacci number un, the nth lucky number ln and the nth prime pn. If you observe any apparent patterns investigate with proofs or counterexamples whether the pattern persists or eventually breaks down.

1.3

The infinitude of primes

In fact it was Euclid who first established that the sequence of primes is endless by proving the following beautiful theorem. Theorem 1.3.1 (Euclid Book 9)

The prime numbers are more than any assigned multitude of prime numbers’—that is, there exist infinitely many primes. Proof (by the method of reductio ad absurdum)

Suppose, to the contrary, that there exist only finitely many primes. Denote them by* p1( = 2), p2( = 3),..., Pt- Form the number N = p, p2 ■ • • p, + 1. By Theorem We retain our restriction that primes are positive.

26

Divisibility

1.1.5, N is divisible by some prime p, say. But px, p2, • •., pt is a list of all the primes—and so p must be one of them, p — Pi, say. Then p:\N and p,\N — 1. Consequently (Exercise l.l.l(ii) pt\N — (N — 1), i.e. p,|l. But this is absurd, by definition of primeness. Thus the supposition that there are only finitely many primes has led to a contradiction. Hence there must be infinitely many. □ To emphasise once again the curious difference that can exist in the methods of the solutions required for seemingly identical problems let us consider the following. Once one knows there exist infinitely many primes, one is soon led to omit 2 and split the rest into two camps; those leaving remainder 3 on division by 4 and those leaving remainder 1: Type 4k + 3: Type 4k+\:

3

7 5

11 *

* 13

19 17

23 *

* 31 * *43... *29 * 37 41 ...

We then ask, quite naturally: Are there infinitely many primes in each list? It turns out that the answer is ‘yes’, although it seems harder to prove this fact for the primes in the second row than for those in the first. (See Theorems 1.3.5 and 3.5.8.) Again, all odd primes greater than 3 are of the form 6k + 1 or 6k+ 5 [why?]. Here, too, one can prove that there are infinitely many of each type, the proof for the latter type again yielding fairly easily (Exercise 1.3.6). On splitting the primes amongst the four classes 8/c + l, 8k + 3, 8k + 5 and 8/c + 7, however, not even the infinitude of the 8k+ 1 type primes is very easy to establish (see Theorem 8.4.6). All this suggests several questions, in fact infinitely many questions! namely: Given any two non-zero integers a, b does there exist in the arithmetic progression am + b (m = 0, 1, 2,...) an infinitude of primes? Clearly we shall have to demand that a and b have no divisor in common which is greater than 1 (Exercise 1.3.5). But what then? In fact we are just 152 years late in asking this question. P. G. L. Dirichlet* answered it completely in 1837. Which way? We leave you with bated breath— or invite you to find out via the index! To return to the problem of the 4/c + 3 primes. It turns out that we require the following fundamental result before we can copy Euclid's argument in Theorem 1.3.1. Let ae Z, a 2s 2. Then we may write a = qxq2■ • ■ qm where each of the q, is a prime.

Theorem 1.3.2

Proof (Using PMI2) If a = 2 the desired conclusion clearly holds, (with m = 1 and qi = 2). So now suppose the claimed result is true for all the integers 2, 3,..., k and suppose that a = k + 1. If k + 1 is prime there is nothing more to prove. If k + 1 - u ■ v is composite where 1 < u s£ v < k + 1 then, by induction, * See p. 53.

1.3 The infinitude of primes

27

each of u, v is expressible as a product of primes. Hence so too is k+\ and the desired result is true using PMI2. □ As trivial examples we offer Examples 1.3.3

12 = 2-2-3; 555, 555 = 3-5-7-1M3-37; 123 456 789 = 3-3-3607-3803.

Notes 1.3.4

(i)

In Theorem 1.3.2 no assertion is made that the 1(n) for various n up to 10 000. Make a conjecture. Try to prove it. Run your programs for higher values of n to test your conjecture further. (For some related pretty pictures see [20].)

1.4 The fundamental theorem of arithmetic

29

2

Modify your program for Problem 1 to examine the behaviour of the number of 6k - 1 and 6k + 1 primes. Consider likewise the number of 8k +1, 8k+ 3, 8k+ 5 and 8k+ 7 primes, up to various limits.

3 Amend Program 1.4 so that (i) only integers that are not multiples of 3 are considered; (ii) primes read from a file are considered. For each of the integers 5 123 471, 1 234 567, 82 994 123, 5 739 281, 7 682 947, 71 264 357, 5 739 877, 7 000 001, 5 256 929, 6 348 751 find out the time it takes your computer to determine (i) whether the integer is prime; (ii) all of its factors if it is composite.

4

5 For each of the following numbers compare the time it takes to check that each of the factors is prime with the time it takes to find the factors given only their product: 6521 x7193 = 469 055, 9137x9697 = 8 860 148, 10 313 x 9833 = 10 140 772.

Write a program to determine the fraction of primes in intervals of size 200 about the integers N = 100, 300, 500,..., 5000. Compute also the values of functions such as 1 / N, 1/exp (N), 1/log (N) and 1/log (log (N)) and comment on the suitability of any of these functions as possible approximations to the density of primes as N increases. 6

1.4

The fundamental theorem of arithmetic

Theorem 1.3.2 and Example 1.3.3 leave open the possibility that a given number may be expressible as a product of primes in two or more distinct ways. We tidy this point up with Theorem 1.4.1 (The Fundamental Theorem of Arithmetic) Let a - q]q2 ■ • • qm, as in Theorem 1.3.2 and suppose also that a = r,r2 • • • r„ where the qt and /) are (positive) primes. Then m — n and the 1, then p\a.

3

Show that: (i) if (a, b) =

1

and c\a + b, then (a, c) — (b, c) — 1; (ii) if k ^ 0

(k e Z), then (ka, kb) = \k\(a, b).

4

Give proofs or counterexamples to the following assertions: (i) if (a, b) =

(c, d), then (a2, b2) = (c2, d2)\ (ii) if (a, b) = (k, I) = 1, where a < b < k < /, then (ka + lb, la + kb) = 1; (iii) (a2, b2) = (a, b)2.

5 Let d = (a,b). Prove (a/d, b/d) = 1. Prove or give a counterexample to: (i) (a/d, b) = 1; (ii) if a\bc, then a/d\c. Suppose a,beZ with (a,b) = 1. If ab = c2 can one deduce that a, b are both cubes? If ab = d2 can one infer that a, b are both squares? (Careful! You are not told a, b e Z 1.) 6

7

From the equality a = mb + r deduce that (a, b) = (b, r).

36

Divisibility

8 (i) Show that if a, b, c are all non-zero then (a, (b, c)) = ((a, b), c). Thus we can unambiguously denote such an expression by (a, b, c). (ii) Setting d ~(a, b, c) show that: if e\a, e\b and e\c, then e\d. (Since d\a, d\b and d\c from (i) we can rightly call (a, b, c) the positive gcd of a, b, c. The extensions to more than three integers is made similarly.) (iii) Find integers a, b, c such that (a, b, c) = 1 and yet (a, b), (b, c) and (c, a) are all greater than 1. 9

Find all common divisors of 1848 and 840.

10 Show that if (m,, m2) = 1 and if d\m]m2, then d = dxd2 where d1\ml and d2\m2. 11 Show that if a,b,ne Z and (b, n) = 1 then exactly one of a + b, a + 2b,... a + nb is divisible by n. [Hint: If none of these has remainder 0 on division by n, then there must be a pair with the same (non-zero) remainder. The difference of these two is divisible by n. But this is impossible.] Deduce that one of 2151, 3151, 4151, 5151, 6151, 7151, 8151 is divisible by 7. Which? 12 If (a, b) > 1 must we have (a + 1, 6 + 1) = 1 ? Given a > b > 0 must there exist a k > 0 such that (a + k, b + k) = 1 ? 13 (i) If c\ab must it be true that c|(c, a)(c, b)2 Prove or give a counter¬ example. (ii) Is (ab, c) — (a, c)(b, c) for all a, b, c> 0? If not, can you determine when it is true? (iii) Prove that if (a, c) = (b, c) — 1 then (ab, c) = 1. (iv) Prove that if c\ab and (b, c) = 1 then c\a. (v) Prove that if a\c and b\c and (a, b) — 1 then ab\c. (vi) Prove that if n,keZ+ and n = (r/s)k where (r, s) = 1, then s = ±1. Deduce that if ffn = r/s then n is the kth power of an integer. 14 Let us define the numerically largest divisor of two integers a, b (not both zero) to be that integer g which satisfies: (i) g is a common divisor of a and b and (ii) g > c for each other common divisor of a and b. Prove that g = (a, b) as defined previously. 15

Find: (i) [223355, 253253]; (ii) [3243,2047],

16 Find integers a, b—other than 18 and 540—such that (a, 6) = 18 and [a, b] = 540. 17 Prove that [a, b] is the least positive integer which is a multiple of a and of b. (Cf. Exercise 14 above.) 18

Is [a, [b, c]] = [[a, b], c] for all a, b, c e Z4"? (Cf. Exercise 8(i) above.)

19 Extend the definition of 1cm to sets of 3 and more (positive) integers. (Cf. Exercise 8 above.) Is [a, b, c](a, b, c) = abc for all a, b, c e Z + ? If not, can you find the correct formula? 20 (Lambert* 1769) Suppose a, b, d,meZ+ are such that a\dm - 1, b\dn - 1 and (a, b) = 1. Show that ab\d[m’n]- 1. * Johann Heinrich Lambert, 26 August 1728 - 25 September 1777.

1.6 The Euclidean algorithm

37

21 Prove that for all a, b, c e Z + we have {[a, £>], c) = [(a, c), (b, c)] and its ‘dual’ [(a, b), c] = ([a, c], [b, c]).

Computer problem 1.5 1 Write a program to determine the gcd and 1cm of two integers a and b by factoring a and b and using Theorems 1.5.5 and 1.5.7.

1.6

The Euclidean algorithm

As intimated at the end of Section 1.5, there is a method which enables us to find (a, b) without factoring either a or b\ it is, to boot, more efficient! The method involves the repeated use of the division algorithm and appears as proposition 2 of Euclid’s 7th book. We call it The Euclidean algorithm (EA) Let a, beZ with b + 0. Proceed by the following steps: Step Step Step Step

(0): (i): (ii): (iii):

set r0=|a|, r, = |b|. Find mls r2eZ such that r0= mxr^ + r2, where 0=£ r2 • • -(^0) is a decreasing sequence of non-negative integers. Hence, for some integer^ we must have r/+, = 0. In that case we have Step (/- 1): Find mf_x, rfeZ such that rf_2= mf_lrf_l + rf, where 0=£ rf< rf_l. Step (/): Find mf, rf+1eZ such that rf_1 = mfrf+ rf+l, where 0=r/+1. Now, starting from step (i), it is not difficult to check (Exercise 1.5.7) that (r0, r,) = (r,, r2) and, from subsequent steps, that similarly, (r,, r2) = (r2, r3) = . . - = (rf, rf+1). But, clearly, (rf,0) = rf. Hence (a, b) = rf, where rf may be identified as ‘the last non-zero remainder in the repeated DA’ To cement these ideas let’s give Example 1.6.1 Find (30 031, 16 579). Now 30 031 = 1.16 579+13 452 16579 = 13 452 = 3127 = 944 = 295 =

1-13 452 + 3127 4- 3127+ 944 3944+ 295 3295+ 59 559+ 0.

38

Divisibility

Hence 59 is the (positive) g.c.d. of 30 031 and 16 579. If we read the above equalities 'backwards’ we get a pleasant surprise. Theorem 1.6.2

Given a, b e Z (not both zero), there exist integers 5, t such

that (a, b) = sa + tb. Proof From step (/- 1) we can write (a, b) = rf = /y_2- «V-i>/-i- Using step (/— 2) we may write rf_x = /y_3 — 2 and hence (a, b) in terms of /y_2 and rf_3. Continuing in this way back to step (i) we finish up expressing iy in terms of a and b, as asserted. Example 1.6.3 59=

= = = =



From Example 1.6.1 we get

i944- 3295= 1-944 - 3-(3127 - 3-944) 10944- 3- 3127 = 10-(13 452-4-3127) -3-3127 10-13 452-43- 3127 = 1013 452-43-(16 579 — 13 452) 53-13 452-43-16 579 = 53-(30 031 -16 579)-43-16 579 53-30 031-96-16 579.

Notes 1.6.4 (i) The coefficients 53 and —96 are by no means uniquely determined (Exercise 1.6.4). (ii) Although it tells us how to obtain the integers s and t, the proof of Theorem 1.6.2 is rather 'messy’. A beautifully elegant proof of Theorem 1.6.2 can be given by calling upon the WO principle (see Exercise 1.6.3). One snag with this elegant proof is that it is, for all practical purposes, an existence proof—that is, it shows that the integers x and t always exist but doesn’t immediately tell you how to find them in any particular case. As presented, the EA and Theorem 1.6.2 do not indicate the most efficient way of obtaining (a, b) as a linear combination of a and b. In order to find this linear combination our method requires us to save all the m„ r, which arise in using the EA in order to use them ‘backwards’ as in Example 1.6.3. In using the computer it would be more efficient to use the m,, r, as we find them, rather than store them. Such a method exists. It is based on the fact that each r, is expressible as a linear combination rk = ska + tkb of a and b and the deduction (from this and step (k) above, where we have rk+l = rk_,— mkrk) that sk+la + tk+lb = {sk_xa + tk_xb) - mk{ska + tkb). That is: Theorem 1.6.5 Let a, b be positive integers. Define s0=l, t0 = 0; sx = 0, tx - 1 and, for k 2s 1: sk+x = sk-x - mksk, tk+l — fk_,— mktk. If r, is the last non-zero remainder in the Euclidean algorithm, then {a, b) = s,a + tfb. □ The reader might also be interested to learn that one can, at the outset, put an upper bound on the number of steps required to complete the Euclidean

1.6 The Euclidean algorithm

39

algorithm. The Frenchman Gabriel Lame*, whom we shall meet again in Chapter 6, used (1844) the Fibonacci sequence to show that the number of steps required is no more than five times the number of digits in the smaller of the two given numbers. A proof is outlined in Exercise 1.7.1. Theorem 1.6.2 has several useful consequences. One, which we shall use immediately, is Corollary 1.6.6 Let a, b e Z be such that (a, b) = 1. Then there exist s, t e Z such that sa + tb = 1. In particular, if p is a prime and p\a, then (a, p) = 1 and there exist u,veZ such that ua + vp = 1. □ In this connection it is useful to make Definition 1.6.7

If a, b £ Z and (a, b) = 1 we say that a and b are coprime (or

relatively prime).

Example 1.6.8 55 555 and 7811 are coprime. (Note that neither number is itself a prime.)

Exercises 1.6 1 Find (37 129, 14 659)—first by factoring each number and then by using the Euclidean algorithm. [Which method is quicker?] 2

Show that, for all n e Z, (5n +2, 12n + 5) = 1.

3 Prove that each pair a, b of integers, not both zero, has a gcd—as follows, (i) Let S be the set {sn + tb: s, t e Z}. (ii) Show that 5 contains positive integers and hence a least one. Call the least one d. (iii) Let w e S. Write w = md + r where 0=£ r < d. Show that r ( = w - md) e S. (iv) Deduce that r = 0 and hence that d\w. (v) Show that a, beS— so that d\a and d\b by (iv). (vi) Note that d = s0a + t0b for certain s0, t0eZ and deduce that if c\a and c\b then c|s0a + t0b = d. (vii) Deduce that d = (a, b). that if d = (a, b) — sa + tb = ua + vb, v = t — ka/d for some integer k.

4

Prove

then

u = s + kb/d

and

Show that if {a, b) — sa + tb, then 5 and t can both be chosen such that |s| ss \b\ and |/| =£ \a\.

5

6

Show that if (a, b) = sa + tb, then (5, t) = 1.

7 Given that sa + tb = 1 prove, or give a counterexample to, the assertions (i) (sa, tb) = 1; (ii) (st, ab) = 1; (iii) (sb, at) = 1. 8 Let a 0 with (a, b) = 1, show that for each integer (a — 1)(6 — 1) the equation xa+ yb = n is soluble using non-negative integers x, y. Show that for precisely half of the integers t from 0 to (a-l)(6 —1) — 1 inclusive the equation is soluble with x, y 0. [Hint: Suppose a < b. The representable integers are 0, a, 2a,... ; b, b + a, . .. ; 2b, 2b + a,. . ., (a - 1)6, (a — 1 )b + a,. .. . Deduce that the number of non-representable integers is [6/a] + [26/a] + • • • + [(a —l)6/a]. To evaluate this see Lemma 8.5.2.] 13

Show that ax + by + cz — d has a solution in integers iff (a, b, c)\d. Find s, t, u e Z such that (105, 150, 288) = 1055 + 150/ + 288u.

1.7

Computing GCDs

The algorithm (EA) described above gives us an easy-to-program method for obtaining the gcd of two numbers which we present below. Program 1.6 10 20 30 40 50 60 70 80

Calculation of gcd using the Euclidean Algorithm

INPUT a,b PRINT "GCD of ";a;" and ";b;" is r=a - INT(a/b)«b a=b b=r IF r 0 GOTO 30 PRINT;a END

We do not need to ensure that a > 6. Why not? Do we need a, 6 > 0? From the above discussion we see that the number of times the loop is repeated is less than 5 times the number of digits in the smaller number. It can also be shown ([10], p. 60) that it a > 6, then the average number of division steps required is 1.941og106. Thus as 6 increases the number of operations increases. Once we reach numbers beyond those which our com¬ puter can handle naturally, the cost of this division increases greatly compared

7.7 Computing GCDs

41

to the cost of addition and subtraction (see Appendix I). It is therefore useful to present an alternative method based on subtraction which, while slightly less efficient for small numbers, is much quicker in handling larger ones. The method is based on the following observations concerning the gcd of two positive integers a and b. (i) (ii) (iii) (iv)

If If If If

a and b are both even then {a, b) = 2{a/2, b/2) (Exercise 1.5.3(ii)). a is even and b odd then (a, b) = (a/2, b). a > b then {a, b) = (a - b, b). a and b are both odd then \a-b\ is even.

The program based on these observations is

Program 1.7

Calculation of gcd using only subtraction and division by two

10 20 24 25 30 40 50 60 70 80 90 100 110 120 130 140

INPUT a,b PRINT "gcd of ";a;" and ";b;" is a=ABS(a):b=ABS(b):REM why ? REM Remove the common power of 2 m = 1 IF a/2INT(a/2) OR b/2INT(b/2) GOTO 90 a = a/2 b = b/2 m = m * 2 GOTO 40 IF a/2 = INT (a/2) THEN a = a/2 IF b/2 = INT (b/2) THEN b = b/2 IF a>b THEN a=a-b ELSE IF b>a THEN b = b-a IF aob GOTO 90 PRINT ;a*m END

The second computational problem relating to the positive gcd of two given numbers a and b is that of representing (a, b) as a linear combination of a and b. One way of performing the computation is to store the quotients and remainders obtained at each stage of the iteration used to determine the gcd and then use these to construct the linear combination as illustrated in Example 1.6.3. This method would require us to estimate at the outset the amount of storage needed for the quotients and remainders which occur. Lame’s result above gives us an upper bound for the dimension and BASIC allows us to declare this dynamically in the program by first determining the number of digits in the smaller number before declaring the dimension. (Of course this increases with the size of the numbers. Furthermore, the number of operations required for storing and recovering the numbers also increases.) We can avoid all these problems by using Theorem 1.6.5 which presents us with an algorithm for constructing the linear combinations as we proceed; it only requires two arrays of size three whatever the size of the numbers involved!

42

Divisibility

Program 1.8

Calculates gcd and expresses it as a linear combination of the two integers

10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 175 180 190

REM gcd(a,b) and linear combination in single step DIM a(3),b(3) INPUT x.y a(1)=1 a(2)=0 a(3)=x b(1)=0 b(2)=l b(3)=y q=INT(a(3)/b(3)) FOR i=l TO 3 r=a(i) - q*b(i) a(i)=b(i) b(i)=r NEXT IF b(3)0 GOTO 100 PRINT "The GCD is ";ABS(a(3)); IF a(3)=-ABS(a(3)) THEN x=-x : y=-y PRINT and equals a(1x;" + a(2) y END

Exercises 1.7 1 Using the notation of Section 1.6, that is, with r0 = |a|, r, = |h| and rf the last non-zero remainder and with un being the nth term of the Fibonacci sequence, prove Lame’s theorem as follows: Show (i) rf^\ = u2; (ii) r/_12s2/y3=2u2= u3. Now use induction together with the inequality rf-k 3= r/_(fc_1)+ r/_(fc_2) to show, for 0=s /=£/- 1, that rf_, ^ u,+2. Deduce that |b| = r, 3= uf+x. Using Exercise 0.5.2(v), show that u/+1 > a '~\ where a = (1 +%/5)/2. Deduce that log10\b\> (/- 1) log10 a > (/- 1) • 5 so that /*£ 5 log10 |b|, as claimed. 2 Show that the number of divisions in applying the Euclidean algorithm to the pair of numbers un+2, un+] of the Fibonacci sequence is exactly n.

Computer problems 1.7 1 Calculate the gcd of 73 524 913 and 5 739 877 using (i) your program for problem 1.5.1, (ii) Program 1.6 and (iii) Program 1.7. Which is quickest? Try other numbers to see if one program is always faster than each of the others. 2 Modify the gcd program so that it also calculates the 1cm [a, b] of two integers.

3

Write a program to determine whether or not two integers are coprime. Modifying the program so that it generates two non-equal random integers between 2 and 100 000, estimate the proportion of pairs of integers that are coprime.

1.8 Factorisation revisited

43

4 Use the relation in Exercise 1.5.8 to write a program to compute the gcd of an arbitrary list of positive integers. 5 Write a program to express the gcd of an arbitrary list of positive integers as a linear combination of the integers in that list.

1.8

Factorisation revisited

We use Corollary 1.6.6 to establish a property which characterises the primes in Z. Theorem 1.8.1 (i) (Euclid Book 7) Let p be a prime and let a, b e Z be such that p\ab. Then p\a or p\b (or both*). (ii) Conversely: if n (5^ —1,0, l)eZ and if, whenever n\ab, we are forced to deduce that n\a or n\b (or both*) then n must be prime. Proof

(i)

Let a, b, p be as given. If p\a there is nothing left to prove. So suppose

that p\a. Now the only divisors of p are -1, 1, -p and p and, of these, only -1 and 1 also divide a. Thus (a, p) = 1. From Corollary 1.6.6 we deduce the existence of s, t e Z such that sa + tp = 1. It follows that sab + tpb = b. But p\ab (given) and p\tpb (clearly!). Hence p\sab + tpb. That is, p\b. We have therefore shown that either p\a or, failing that, p\b—as required. (ii) (by reductio) Let us assume that n (3*2) is not a prime. Then n = kl (where 1 < k < n and 1 < l < n) is composite. But then n\kl and yet n\k and n\l. This contradicts the given property of n. Hence the assumption that n is composite is false. Thus n is prime—as required. □ Notes 1.8.2 (i) Theorem 1.8.1 is a vital ingredient in a more direct proof of Theorem 1.4.1 given below. (ii) Theorem 1.8.1 easily extends to: Let p be a prime and let au a2,..., an e Z. If p\axa2 • • • an, then p\a, for some i (1 *£/*£«). The more direct (and more transparent—but less pretty) proof of Theorem 1.4.1 then goes, very informally, as follows. Suppose a = qxq2-■ ■ qm = rxr2-■ ■ rn

(*)

* In mathematics ‘or’ is always assumed to include the possibility of both occurrences. (Thus if at your maths professor’s house you are asked ‘white wine or red?’ you should—even if you drink only white or drink only red or if you want wine but don’t mind which— reply ‘yes please’. Of course, you might end up with a glass of the ‘wrong’ colour or conceivably with a glass of each!)

44

Divisibility

where the g, and r, are primes and where, WLOG*, we may as well suppose that