Rosen - Elementary Number Theory and Its Applications (001-100)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 100

Elementary

Number
Theory
andlts
Applications

KennethH. Rosen
AT&T Informotion
SystemsLaboratories
(formerly part of
Bell Laborotories)

A
YY
ADDISON-WESLEY
PUBLISHING COMPANY
Read ing, Massachusetts
Menlo Park, California
London Amsterdam
Don Mills, Ontario Sydney
Cover: The iteration of the transformation

\ n/2 if n is even
T(n) :
l Qn + l)/2 if n is odd

is depicted. The Collatz conjecture assertsthat with any


starting point, the iteration of ?"eventuallyreachesthe integer
o n e . ( S e eP r o b l e m 3 3 o f S e c t i o n l . 2 o f t h e t e x t . )

Library of Congress Cataloging in Publication Data

Rosen, Kenneth H.
Elementary number theory and its applications.

Bibliography: p.
Includes index.
l. Numbers, Theory of. I. Title.
QA24l.R67 1984 512',.72 8 3 - l1 8 0 4
rsBN 0-201-06561-4

Reprinted with corrections, June | 986

Copyright O 1984 by Bell Telephone Laboratories and


Kenneth H. Rosen. All rights reserved. No part of this
publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic,
mechanical,photocopying, recording, or otherwise, without
prior written permission of the publisher. printed in the United
States of America. Published simultaneously in Canada.

DEFGHIJ_MA_8987
Preface

Number theory has long been a favorite subject for students and teachersof
mathematics. It is a classical subject and has a reputation for being the
"purest" part of mathematics, yet recent developments in cryptology and
computer science are based on elementary number theory. This book is the
first text to integrate these important applications of elementary number
theory with the traditional topics covered in an introductory number theory
course.

This book is suitable as a text in an undergraduatenumber theory course at


any level. There are no formal prerequisitesneeded for most of the material
covered, so that even a bright high-school student could use this book. Also,
this book is designed to be a useful supplementarybook for computer science
courses,and as a number theory primer for computer scientistsinterested in
learning about the new developmentsin cryptography. Some of the important
topics that will interest both mathematics and computer sciencestudents are
recursion,algorithms and their computationai complexity, computer arithmetic
with large integers, binary and hexadecimal representations of integers,
primality testing, pseudoprimality,pseudo-randomnumbers, hashing functions,
and cryptology, including the recently-invented area of public-key
cryptography. Throughout the book various algorithms and their
computational complexitiesare discussed.A wide variety of primality tests are
developedin the text.

Use of the Book

The core material for a course in number theory is presentedin Chapters 1,


2, and 5, and in Sections 3.1-3.3 and 6.1. Section 3.4 contains some linear
algebra; this section is necessary background for Section 7.2; these two
sections can be omitted if desired. Sections 4.1, 4.2, and 4.3 present
traditional applications of number theory and Section 4.4 presents an
application to computer science; the instructor can decide which of these
sectionsto cover. Sections 6.2 and 6.3 discussarithmetic functions. Mersenne
primes, and perfect numbers; some of this material is used in Chapter 8.
Chapter 7 covers the applications of number theory to cryptology. Sections
7.1, 7.3, and 7.4, which contain discussionsof classical and public-key
vt Preface

cryptography,should be included in all courses.Chapter 8 deals with primitive


roots; Sections 8.1-8.4 should be covered if possible. Most instructors will
want to include Section 8.7 which deals with pseudo-randomnumbers.
Sections 9.1 and 9.2 are about quadratic residues and reciprocity, a
fundamental topic which should be covered if possible;Sections 9.3 and 9.4
deal with Jacobi symbols and Euler pseudoprimesand should interest most
readers. Section 10.1, which covers rational numbers and decimal fractions.
and Sections I 1.1 and I 1.2 which discussPythagoreantriples and Fermat's
last theorem are coveredin most number theory courses. Sections 10.2-10.4
and I 1.3 involve continued fractions; these sectionsare optional.

The Contents

The reader can determine which chapters to study based on the following
descriptionof their contents.
Chapter I introduces two importants tools in establishing results about the
integers, the well-ordering property and the principle of mathematical
induction. Recursive definitions and the binomial theorem are also developed.
The concept of divisibility of integers is introduced. Representations of
integers to different bases are described, as are algorithms for arithmetic
operations with integers and their computational complexity (using big-O
notation). Finally, prime numbers, their distribution, and conjectures about
primes are discussed.

Chapter 2 introduces the greatest common divisor of a set of integers. The


Euclidean algorithm, used to find greatest common divisors, and its
computational complexity, are discussed, as are algorithms to express the
greatest common divisor as a linear combination of the integers involved. The
Fibonacci numbers are introduced. Prime-factorizations, the fundamental
theorem of arithmetic, and factorization techniques are covered. Finally,
linear diophantine equationsare discussed.

Chapter 3 introduces congruences and develops their fundamental


properties. Linear congruencesin one unknown are discussed,as are systems
of linear congruences in one or more unknown. The Chinese remainder
theorem is developed,and its application to computer arithmetic with large
integers is described.
Chapter 4 developsapplicationsof.congruences. In particular, divisibility
tests, the perpetual calendar which provides the day of the week of any date,
round-robin tournaments,and computer hashing functions for data storage are
discussed.
Preface vtl

Chapter 5 developsFermat's little theorem and Euler's theorem which give


some important congruencesinvolving powers of integers. Also, Wilson's
theorem which gives a congruencefor factorials is discussed. Primality and
probabilistic primality tests based on these results are developed.
Pseudoprimes, strong pseudoprimes, and Carmichael numbers which
masquaradeas primes are introduced.
Chapter 6 is concernedwith multiplicative functions and their properties.
Special emphasisis devotedto the Euler phi-function, the sum of the divisors
function, and the number of divisors function and explicit formulae are
developed for these functions. Mersenne primes and perfect numbers are
discussed.

Chapter 7 gives a thorough discussionof applicationsof number theory to


cryptology, starting with classical cryptology. Character ciphers based on
modular arithmetic are described,as is cryptanalysisof these ciphers. Block
ciphers based on modular arithmetic are also discussed. Exponentiation
ciphers and their applications are described, including an application to
electronic poker. The concept of a public-key cipher system is introduced and
the RSA cipher is describedin detail. Knapsackciphers are discussed,as are
applicationsof cryptographyto computer science.
Chapter 8 includes discussionsof the order of an integer and of primitive
roots. Indices, which are similar to logarithms, are introduced. Primality
testing basedon primitive roots is described. The minimal universalexponent
is studied. Pseudo-random numbers and means for generating them are
discussed.An applicationto the splicingof telephonecablesis also given.
Chapter 9 covers quadratic residues and the famous law of quadratic
reciprocity. The Legendreand Jacobi symbolsare introduced and algorithms
for evaluating them are developed. Euler pseudoprimesand a probabilistic
primality test are covered. An algorithm for electronically flipping coins is
developed.

Chapter l0 coversrational and irrational numbers,decimal representations


of real numbers,and finite simple continuedfractionsof rational and irrational
numbers. Special attention is paid to the continued fractions of the square
roots of po"itive integers.
Chapter 1l treats some nonlinear diophantine equations. Pythagorean
triples are described. Fermat's last theorem is discussed. Finallv. Pell's
equation is covered.
vill P reface

Problem Sets

After each sectionof the text there is a problem set containing exercisesof
various levelsof difficulty. Each set containsproblemsof a numerical nature;
these should be done to develop computational skills. The more theoretical
and challenging problems should be done by studentsafter they have mastered
the computationalskills. There are many more problemsin the text than can
be realistically done in a course. Answers are provided at the end of the book
for selectedexercises,mostly those having numerical answers.

Computer Projects

After each section of the text there is a selectionof computer projects that
involve concepts or algorithms discussedin that section. Students can write
their programs in any computer language they choose, using a home or
personal computer, or a minicomputer or mainframe. I encouragestudents to
use a structured programming languagesuch as C, PASCAL, or PL/ 1, to do
these projects. The projects can serve as good ways to motivate a student to
learn a new computer language, and can give those students with strong
computer science backgrounds interesting projects to tie together computer
scienceand mathematics.

Unsolved Problems

In the text and in the problem setsunsolvedquestionsin number theory are


mentioned. Most of these problems have eluded solution for centuries. The
reader is welcome to work on these questions,but should be forewarned that
attempts to settle such problems are often time-consuming and futile. Often
people think they have solved such problems,only to discover some subtle flaw
in their reasoning.

Bibliography

At the end of the text there is an extensivebibliography,split into a section


for books and one for articles. Further, each section of the bibliography is
subdivided by subject area. In the book section there are lists of number
theory texts and references, books which attempt to tie together computer
scienceand number theory, books on some of the aspectsof computer science
dealt with in the text, such as computer arithmetic and computer algorithms,
books on cryptography, and general references.In the articles section of the
bibliography, there are lists of pertinent expository and research papers in
number theory and in cryptography. These articles should be of interest to the
reader who would like to read the original sources of the material and who
wants more details about some of the topics coveredin the book.
Preface tx

Appendix

A set of five tables is included in the appendix to help studentswith their


computations and experimentation. Students may want to compile tables
different than those found in the text and in the appendix; compiling such
tables would provide additional computer projects.

List of Symbols

A list of the svmbols used in the text and where they are defined is
included.

Acknowledgments

I would like to thank Bell Laboratoriesand AT&T Information Systems


Laboratories for their support for this project, and for the opportunity to use
the UNIX system for text preparation. I would like to thank George Piranian
for helping me develop a lasting interest in mathematics and number theory.
Also I would like to thank Harold Stark for his encouragementand help,
starting with his role as my thesisadvisor. The studentsin my number theory
courses at the University of Maine have helped with this project, especially
Jason Goodfriend, John Blanchard, and John Chester. I am grateful to the
various mathematicians who have read and reviewed the book, including Ron
Evans, Bob Gold, Jeff Lagarias and Tom Shemanske. I thank Andrew
Odlyzko for his suggestions,Adrian Kester for his assistancein using the
UNIX system for computations, Jim Ackermann for his valuable comments,
and Marlene Rosen for her editing help.
I am particularly grateful to the staff of the Bell Laboratories/American
Bell/AT&T Information Services Word ProcessingCenter for their excellent
work and patience with this project. Special thanks go to Marge Paradis for
her help in coordinating the project, and to Diane Stevens, Margaret
Reynolds, Dot Swartz, and Bridgette Smith. Also, I wish to express my
thanks to Caroline Kennedy and Robin Parson who typed preliminary versions
of this book at the University of Maine.
Finally, I would like to thank the staff of Addison-Wesley for their help. I
offer special thanks to my editor, Wayne Yuhasz, for his encouragement,aid,
and enthusiasm.

Lincroft, New Jersey Kenneth H. Rosen


December.1983
Contents

Chapterl. The Integers

l.l The well-ordering 4


1.2 Divisibility l8
1.3 Representations of int;;;;;....-'.....-'-.'......... 24
t.4 Computer operationswith integers............ 33
1.5 Prime numbers... 45

Chapter2. Greatest Common Divisors and Prime Factorization

2.1 Greatest common divisors 53


2.2 The Euclideanalgorithm ........... 58
2.3 The fundamentaltheorem of arithmetic ............ 69
2, 4 Factorization of integers and the Fermat numbers 79
2.5 Linear diophantineequations............... 87

Chapter3. Congruences

3.1 Introduction to congruences 9l


3.2 Linearcongruences.............. 102
3.3 The Chinese remainder theorem 107
3.4 Systemsof linear congruences.............. I 16

Chapter4. Applications of Congruences

4.1 D i v i s i b i l i t yt e s t s . . . . . . . . . .. 129
4.2 T h e p e r p e t u a cl a l e n d a r . . . . . . . . . . . . . 134
4.3 R o u n d - r o b i nt o u r n a m e n t s . . . . . . . . . . .. 139
4. 4 Computer file storageand hashingfunctions............... l4l
Contents xl

Chapter 5. Some Special Congruences

5.1 Wilson's theorem and Fermat's little theorem 147


5.2 Pseudoprimes.............. .. 152
5.3 Euler's theorem 16l

Chapter6. MultiplicativeFunctions

6.1 E u l e r ' sp h i - f u n c t i o n. . . . . . . . . . . . . . . 166


6.2 T h e s u m a n d n u m b e ro f d i v i s o r s . . . . . . . . . . . . . . 174
6.3 Perfect numbersand Mersenneprimes 180

Chapter 7. Cryptology

7 .l Character ciphers 188


7 .2 Block ciphers 198
7.3 Exponentiationciphers............... .. 205
7.4 Public-keycryptography............. 212
7.5 Knapsack ciphers 219
7.6 Some applicationsto computer science 227

Chapter 8. Primitive Roots

8.1 The order of an integer and primitive roots 232


8.2 Primitive roots for primes 238
8.3 Existenceof primitive roots 243
8.4 Index arithmetic 252
8.5 Primality testing using primitive roots......... 263
8.6 Universal exponents. 268
8.7 Pseudo-random numbers............ .. 275
8.8 The splicingof telephonecables .. 280

Chapter 9. Quadratic Residuesand Reciprocity

9.I Quadratic residues 288


9.2 Quadratic reciprocity .. 304
9.3 The Jacobi symbol 314
9.4 Euler pseudoprimes............. 325
xtl Contents

Chapter 10. Decimal Fractions and Continued Fractions

10.1 Decimal fractions... 336


10.2 Finite continuedfractions 350
10.3 Infinite continued fractions 361
10.4 Periodic continued fractions 315

Chapter I l. Some Nonlinear Diophantine Equations

l.l Pythagoreantriples.... 391


t.2 F e r m a t ' sl a s t t h e o r e m. . . . . . . . . . . . . 397
1.3 Pell'sequations 401

Appendix.. 410
Answers to selected problems 426
Bibliography............. 438
List of symbols.... 445
Index 447
lntroduction

Number theory, in a general sense, is the study of numbers and their


p r o p e r t i e s .I n t h i s b o o k ,w e p r i m a r i l y d e a l w i t h t h e i n t e g e r s , 0 ,+ 1 , + 2 , . . . .
We will not axiomatically define the integers, or rigorously develop integer
arithmetic.l Instead, we discussthe interestingpropertiesof and relationships
between integers. In addition, we study the applicationsof number theory,
particularly thosedirected towardscomputer science.
As far back as 5000 years ago, ancient civilizations had developedways of
expressingand doing arithmetic with integers. Throughout history, different
methods have been used to denote integers. For instance, the ancient
Babyloniansused 60 as the base for their number system and the Mayans
used 20. Our method of expressing integers, the decimal system,was first
developed in India approximately six centuries ago. With the advent of
modern computers, the binary system came into widespreaduse. Number
theory has been used in many ways to devise algorithms for efficient computer
arithmetic and for computer operationswith large integers.
The ancient Greeks in the school of Pythagoras, 2500 years ago, made the
distinction betweenprimes and composites. A prime is a positive integer with
no positive factors other than one and the integer itself. In his writings,
Euclid, an ancient Greek mathematician, included a proof that there are
infinitely many primes. Mathematicians have long sought formulae that
generate primes. For instance, Pierre de Fermat, the great French number
theorist of the seventeenthcentury, thought that all integers of the form
22' + 1 are prime; that this is false was shown, a century after Fermat made
this claim, by the renowned Swiss mathematician Leonard Euler, who
demonstratedthat 641 is a factor of 22' + | .
The problem of distinguishing primes from compositeshas been extensively
studied. The ancient Greek scholarEratosthenesdeviseda method, now called

l. S u c h a n a x i o m a t i c d e v e l o p m e n to f t h e i n t e g e r sa n d t h e i r a r i t h m e t i c c a n b e f o u n d i n L a n d a u
t6ll.
Introduction

the sieve of Eratosthenes, that finds all primes less than a specified
limit. It
is inefficient to use this sieve to determine whether a particular integer
is
prime. The problem of efficiently determining whether an integer is prirne
has
long challengedmathematicians.

Ancient Chinese mathematiciansthought that the primes were precisely


those positive integers n such that n divides 2' - 2. Fermat showed that if
n
is prime, then n does divide 2n - 2. However, by the early nineteenth
century, it was known that there are compositeintegersn such that n divides
2n - 2, such as n : 341 . These compositeintegers are called pseudoprimes
Becausemost compositeintegers are not pseudoprimes,it is possibleto develop
primality tests based on the original Chinese idea, together with extra
observations. It is now possibleto efficiently find primes; in fact, primes with
as many as 200 decimal digits can be found in minutes of computer time.

The fundamental theorem of arithmetic, known to the ancient Greeks,


says that every positive integer can be written uniquely as the product of
primes. This factorization can be found by trial division of the integer by
primes less than its square-root; unfortunately, this method is very time-
consuming. Fermat, Euler, and many other mathematicians have produced
imaginative factorization techniques. However, using the most efficient
technique yet devised, billions of years of computer time may be required to
factor an integer with 200 decimal digits.

The German mathematician Carl Friedrich Gauss, consideredto be one of


the greatest mathematicians of all time, developed the language of
congruences in the early nineteenth century. When doing certain
computations,integers may be replaced by their remainders when divided by a
specific integer, using the language of congruences. Many questions can be
phrased using the notion of a congruencethat can only be awkwardly stated
without this terminology. Congruenceshave diverse applications to computer
science,including applications to computer file storage, arithmetic with large
integers,and the generationof pseudo-randomnumbers.

One of the most important applications of number theory to computer


science is in the area of cryptography. Congruencescan be used to develop
various types of ciphers. Recently, a new type of cipher system, called a
public-key cipher system, has been devised. when a public-key cipher is
used, each individual has a public enciphering key and a private deciphering
key. Messagesare encipheredusing the public key of the receiver. Moreover,
only the receiver can decipher the message,since an overwhelming amount of
computer time is required to decipher when just the enciphering key is known.
The most widely used public-key cipher system relies on the disparity in
computer time required to find large primes and to factor large integers. In
lntrocluction

particular, to produce an enciphering key requires that two large primes be


found and then multiplied; this can be done in minutes on a computer. When
these large primes are known, the decipheringkey can be quickly found. To
find the deciphering key from the enciphering key requires that a large
integer, namely the product of the large primes, be factored. This may take
billions of years.
In the following chapters,we discussthese and other topics of elementary
number theory and its applications.
1
The Integers

1.1 The Well-OrderingProperty


In this section,we discussseveral important tools that are useful for proving
theorems. We begin by stating an important axiom, the well-ordering
property.

The Well-Ordering Property. Every nonempty set of positive integers has a


least element.
The principle of mathematical induction is a valuable tool for proving
results about the integers. We now state this principle, and show how to prove
it using the well-ordering property. Afterwards, we give an example to
demonstrate the use of the principle of mathematical induction. In our study
of number theory, we will use both the well-ordering property and the
principle of mathematical induction many times.

The Principle of Mathematical Induction. A set of positive integers that


contains the integer I and the integer n I I whenever it contains n must be
the set of all positive integers.

Proof. Let S be a set of positive integers containing the integer I and the
integer n * | whenever it contains n. Assume that S is not the set of all
positive integers. Therefore, there are some positive integers not contained in
.S. By the well-ordering property, since the set of positive integers not
contained in S is nonempty, there is a least positive integer n which is not in
. S . N o t e t h a t n 1 1 , s i n c el i s i n S . N o w s i n c en ) l , t h e i n t e g e r n - 1 i s
l.l The Well-Ordering ProPertY

a positive integer smaller than n, and hence must be in S. But since S


contains n - l, it must also contain (n-t) + | : n, which is a contradiction,
since n is supposedlythe smallest positive integer not in S. This shows that S
must be the set of all positive integers. tr
To prove theorems using the principle of mathematical induction, we must
show two things. We must show that the statement we are trying to prove is
true for l, the smallest positive integer. In addition, we must show that it is
true for the positive integer n * I if it is true for the positive integer n. By
the principle of mathematical induction, one concludes that the set S of all
positive integers for which the statement is true must be the set of all positive
integers. To illustrate this procedure, we will use the principle of
mathematical induction to establish a formula for the sum of the terms of a
geometric progression.

Definition. Given real numbers 4 and r. the real numbers


a , a r , e r 2 ,o t 3 r . . .

are said to form a geometric progression. Also, a is called the initial term
and r is called the common ratio.

Exa m ple. T he num b e rs 5 , -1 5 ,4 5 , -1 3 5 ,... fo rm a geometri c progressi on


with initial term 5 and common ratio -3.
In our discussion of sums, we will find summation notation useful. The
following notation representsthe sum of the real numberse1, o2,...,on.

2oo:er*az* lan
k-l

We note that the letter k, the index of summation, is a "dummy variable" and
can be replaced by any letter, so that
nn

5,
k-l
ak: 2 oi
j-t i-l

Example. We see that


The Integers

)
2j:I+2+3+4+5:15,
j-r
)
2t2:2+2+2+2+2:10,
j-r

and
)
2 2i : 2 * 22+ 23+ 24+ 2s : 62 .
j-1

We also note that in summation notation, the index of summation may


range betweenany two integers,as long as the lower limit does not exceedthe
upper limit. If m and h are integers such that z ( n, then

b oo:am*a^a1* *an.
k-m

For instance.we have


5
> k 2 : 3 3+ 4 2+ 5 2 : 5 0 ,
k;t

> 3k:30 + 3t + 32: 13,


fr:0

and
I

k--2

We now turn our attention to sums of terms of geometricprogressions.The


su m of t he t er m s e ) e r, o r2 ,...,a rn i s
n

2ori:e*ar*ar2+ *arn,
j-0

where the summation beginswith 7 : g. We have the following theorem.

Theorem l.l. If a and r ^re real numbersand r * l. then


1.1 The Well-OrderingProperty

n),,narn*l-Q
(1.1) E ori
: a * ar i*a rar2
-t + r ' ' : T: T
r* a arn .
j:o

Proof. To prove that the formula for the sum of terms of a geometric
progressionis valid, we must first show that it holds for n : l. Then, we must
show that if the formula is valid for the positive integer n, it must also be true
for the positive integer n * l.
To s t ar t t hings o ff, l e t n : l . T h e n , th e l e ft si de of (t.t) i s a * ar, w hi l e
o n t he r ight s ideof (1 .1 ) w e h a v e
arL-a _ a?z-t) _ ab*l)(r-1) a(r*l) : a * ar
r-l r-l T:

So the formula is valid when n : l.

N ow we as s um eth a t (1 .1 ) h o l d s for the positive integer n. That is, we


assumethat

0.2) alar+arz+ 'tar'-arn*l-Q


I

We must show that the formula also holds for the positive integer n * l.
What we must show is that

(t.:) or@+t)+t_o ar'+2-e


a*ar+ar2+ * arn * arn*l :
r-l r-l
To show that (1.3) is valid, we add orn*r to both sidesof (1.2), to obtain

arn+t:o
(t.+) (a*ar*ar2+...+arn) * a r ' + r- + arr+t,
r-l

The left side of (t.+) is identical to that of (1.3). To show that the right sides
are equal, we note that
arn*l-a 1 arn+l-e , or'*l (r- I )
T A ^r - n r r _ T-
r- I r-l r-1
orn*l-a*ar'+Z arn*l

:
r-l

Since we have shownthat 0.2) i m p l i e s (t.:), w e can concl udethat (t.t)


The Integers

holds for all positive integers n. tr

Example. Let n be a positive integer. To find the sum

bro:r*2+22+ *2',
k:0

we use Theorem l.l with e : I and r : 2, to obtain


1n*l _ I
l+2+22+ . J- 1n : rn*l_r
2-l

Hence, the sum of consecutivenonnegative powers of 2 is one less than the


next largest power of 2.
A slight variant of the principle of mathematical induction is also sometimes
useful in proofs.

The Second Principle of Mathematical Induction. A set of positive integers


which contains the integer 1, and which has the property that if it contains all
th e pos it iv eint eg e rs1 ,2 ,..., k , th e n i t a l s o c ontai nsthe i nteger k + l , must
be the set of all positive integers.

Proof. Let T be a set of integers containing I and containing k + I if it


co nt ains 1, 2, . . . , k . L e t S b e th e s e t o f a l l p osi ti vei ntegersn such that al l
the positive integers less than or equal to n are in Z. Then I is in S, and by
the hypotheses,we see that if k is in S, then k + | is in S. Hence, by the
principle of mathematical induction, S must be the set of all positive integers,
so clearly T is also the set of all positive integers. tr

The principle of mathematical induction provides a method for defining the


values of functions at positive integers.

Definition. We say the function f is defined recursively if the value of f at I


is specifiedand if a rule is providedfor determiningf h*l) from f h) .

If a function is defined recursively, one can use the principle of


mathematical induction to show it is defined uniquely at each positive integer.
(See problem 12 at the end of this section.)

We now give an example of a function defined recursively. We define the


factorial function f fu) : nt . First, we specify that
1.1 The Well-Ordering ProPertY

f(r): I ,
and then we givethe rule for finding f h*1) from f fu), namely
f h+r) : (n+r)'ffu).
These two statementsuniquely define r!.
To find the value of f G) : 6! from the recursive definition of f h) : nl,
use the secondproperty successively,as follows
(2) :6's'4'3'2f0).
f 6) :6.f (5) : 6.5.f(4) : 6.s.4'f(3) : 6's'4'3'f
We now use the first statement of the definition to replacef 0) by its stated
value l. to concludethat
6 l : 6 ' 5 ' 4 ' 3 ' 2 ' :l 7 2 0 .

In general, by successivelyusing the recursive definition, we see that n! is the


product of the first n positive integers,i.e.

n! : l'2'3 n

For convenience,and future use, we specify that 0! : l.


We take this opportunity to define a notation for products, analogous to
summation notation. The product of the real numbers a1, a2,...,a, is denoted
by

ft o, : ere2 an
j -r

The letter 7 above is a "dummy variable", and can be replaced arbitrarily.

Example. To illustrate the notation for products we have


)
fI j:l'2'3'4'5:120.
j-r
5
I I 2 : 2 . 2 . 2 . 2 . 22: 5: 3 2 .
j-r
5
fI Zi : 2.22.23.24.2s: 2r5
j-r
l0 The Integers

We note that with this notation, n ! : fI .


j -r ,r
Factorials are used to define binomial cofficients.

Definition. Let m and k be nonnegativeintegers with k 4 m. The


r)
binomial
cofficien,lT I isoenneo
uy
(^ /
r)
l*| mt
t r t : -

lk J kt(m_k)t

l^)
In computing we see that there is a good deal of cancellation,because
lO ,J,
l^) : - - m; t . 2 . 3. . . @ - k ) @ - k + t ) . . . t u - t ) m
lk ) kt@_k)l k! t.2.3 fu-k)
(m-k+r) ( m - r )m
kt

Example.To evaluatethe binomialcoefficien,


fzl
we notethat
L, ,J,
r\
1 7| : 7 t : 1 . 2 . 3 . 4 . s . 6 . 7s . 6 . 7
f3J 3t4t r23.r234:E:i)'
We now prove some simple propertiesof binomial coefficients.

Proposition 1.2. Let n and k be nonnegativeintegerswith k ( n . Then

(i)
[;]:[;]:,
r) r )
( i i ) l l l : -l ' . 1
fkj l,-t,)'
Proof. To see that (i) is true, note that
1.1 The Well-OrderingProperty 11

[;]:# :n'':l
nt

and

To verify (ii), we seethat


t;] _n,._
n !0!
\:t

frl
l,l:
n; :-:l nt lr ,l
l- tr
| . kJ kth-k)t t u - k ) r ( n -h - k ) ) t ln-* )'
An important property of binomial coefficientsis the following identity.

Theorem 1.2. Let n and k be positive integers with n > k. Then

|',]*, I n I _ |,,*'l
r
loj [o-,J:I )
Proof. We perform the addition

[;]. lr:,
by using the c om m o nd e n o mi n a to rftl (n -k + t)!. Thi s gi ves

t. +
Uc lr\,
n th - k t l )
ktfn-k+l\
-
n tk
ktJtt-t(+il
nl((n-k +r) +k)
k th - k + t ) t
ntfu*l)
klfu-k+r)t
(n+l)!
kth-k +r)t
[l l nn + rI
u
f k )
t2 The Integers

Using Theorem 1.2, we can easily construct Pascal's triangle, which


displavsthe binomial coefficients. In this triangle, the binomial coefficient
|,,]
rs t he ( k + t)ttr n u m b e r i n th e (n + l )th row . The fi rst ni ne row s of
|.r,l
Pascal'st r ianglea re d i s p l a y e di n F i g u re l .l .

I
ll
r2l
l33l
r4641
15101051
1615201561
172135352171
18285670562881

'Plr"urt

Figure1.1. triangle.

We see that the exteriornumbersin the triangleare all l. To find an


interiornumber,we simplyadd the two numbersin the positionsabove,and to
either side,of the positionbeing filled. From Theorem1.2, this yieldsthe
correctinteger.
occur in the expansions
Binomial coefficients of powersof sums. Exactly
how they occuris describedby the binomial theorem.

The BinomialTheorem. Let x and y be variablesand n a positiveinteger.


Then

:
(x*y)n y'+
-2 2
l:)..
[;]".. [T]".-',.
+ l,:r)*r.-,+ [,:,]'y n - +l:),'
or using summation notation,
1.1 The Well-Ordering ProPertY l3

^ (n]
G + y ) n: 2 l\ J; ll * " - t y t
j-0

We prove the binomial theorem by mathematical induction. In the proof we


make use of summation notation.

Proof. We use mathematical induction. When n : l, according to the


binomial theorem. the formula becomes

(x*y)r-frlfrl +
loj"'.yoI,,J"or'
But because
lrlfrl s t a t e st h a t ( x + y ) r : x *y, w h i c hi s
lnl: lil:t,this
t"J \^/
obviously true.
We now assume the theorem is valid for the positive integer n, that is, we
assumethat
^ fn)
G+ y ) n: 2 l , l r ' - i r i .
j-0 \r )

We must now verify that the correspondingformula holds with n replaced by


n * l, assumingthe result holds for n. Hence, we have
(x+y)n+r - (xty)"(x+y)
'l
: l, |,,.l I
l a l\ri l)" - t ' l l ( x + r )
|.i:o J
, lnl , fr)
j-0 \r ) j:0 \J ./

We see that by removing terms from the sums and consequently shifting
indices.that
t4 The Integers

21,).'-'."'
2l;).'-'.',' : In+l +

and

:'Al,).'-'''.'
3l:).'-'''*' * yn+t

:21'!'1"-'*' yj + yn*t

Hence, we find that


't
n I
( x *Y )' + r - xn+r +> lxn-i+tri I yn+t
j-r I

By Theorem 1.2, we have

so we conclude that
t;l+ [,1']: [';']
,

- ,,*, + bl':'fx,-i*,ri
k+y),,'+r * yn+r
I r ) i-t
n * t [ n + rI
- S I l*n+t-iri
t 1 ^l . j )
This establishesthe theorem. u
We now illustrate one use of the binomial theorem. If we let x : y : l. we
see from the binomial theorem that

^ lrl , rl lnl
2 n: ( t + t ) , : ) :
l\ r r )l t , - r l i j -)o LJ,l
j-0

This formula showsthat if we add all elementsof the fu+l)th row of Pascal's
triangle, we get 2n. For instance,for the fifth row, we find that
1.1 The Well-OrderingProPertY 15

. . . . :, +4+6+4+,:,6:24
[;] [l] [l] [l] [l]

l.l Problems

l. Find the values of the following sums

l0 l0
a) >2 c) 2j'
j-r j-r

l0 t0
u) 2i o) 22i.
j-l j-r

2. Find the values of the following products

55
i l j -rl r 2 c) r. j'
)
b) trj 0) il2i
j-t j-l

3 . Find n ! for n equal to each of the first ten positive integers.

4.
fro)frolfrolfrol frol
Find
lo,|'|.,.l'I r.l'I tJ'^na
lroJ'
|'qI fgI froI
5 . Find the binomial coefficients and o andverirvthat
l',l' loJ' I ,J'
fnl , fnl f,ol
lrj*loj: loJ
6 . Show that a nonempty set of negative integers has a largest element.
7 . Use mathematical induction to prove the following formulae.

a) >,i:t+2+3+ + ,:n(nlD.
j-l L

.t n (n+l) (2n+l)
U) 2i': 12+22+32+ + , a

j-l 6
t6 The Integers

| 12
c ) i . r ' : t ' + 2 3+ 3 3+ * n3: | 't'ftl I
i-tt2l
8. Finda formula
rcrjft Zi.
-l

9. Use the principle of mathematical induction to show that the value at each
positive integer of a function defined recursivelyis uniquely determined.

r0. what function f (n) is defined recursively by f 0) : 2 and f (n+D : 2f (n)


for n)l?

ll. I f g i s d e f i n e d r e c u r s i v e l yb y g ( l ) : 2 and g(n) :2sb-D for n 7 2,


what is S(02

t2. The second principle of mathematical induction can be used to define functions
recursively. We specify the value of the function at I and give a rule for finding
f h+l) from the values of f at the first n positive integers. Show that the
values of a function so defined are uniquely determined.

t3. We define a function recursively for all positive integers n bV (l) : l,


"f
f (2):5, and for n 2 2, f h+t):f h) + 2f (n-t). Show that f (n) :
2^ + el)n, using the secondprinciple of mathematical induction.

14. a) Let n be a positive integer. By expanding (l+(-l))'with the binomial


theorem. show that

, fr)
) (-r)o : o.
lrJ

b) usepart(a),andthefactthat > f;l :2' , to find


\'' J t-o

f,l* f,l* l,l *


loj IrJ loj
and

[,lf,l|,,l
['J*l,J* I'J*
c) Findthesuml -2+22-23 + +2too.

15. Show by mathematical induction that if n is a positive integer, then


(2n)t < 22'(nl)z.
1.1 The Well-Ordering ProPertY t7

16. The binomial coefficients x is a variable, and n is a positive integer,


[;],*nr."

can be defined recursivelyby the equations : x and


[l ]

| .I ,_n [,1
In+tJ:R l;l
|.".l x! ,
a)Showthatifxisapositiveinteger,then[oJ:ffi,wherekisan
integerwithl(k(x.

.
b)
["]
S h o w t h a tl - l +
[*l
1.,, | :
f'+rl
l--*, l,whenevernisapositiveinteger.
l,?J lt?+rj ln,'t
t 7 . In this problem, we develop the principle of inclusion - exclusion. Suppose
that S is a set with n elements and let Pr, P2,.,., P, be t different properties
that an element of S may have. Show that the number of elements of S
possessingnone of the / properties is

n -ln(rr) + n(p) + + n@)l


) n ( P t , P r+)
+ l n ( P t , P z+ + n(P,-r,P,)l
- { n ( P r , P z , P t )* n ( P r P z , P q ) + * n(P,-2,P,4,P,)|
+ + (-l)'n (P1,P2,...,P,),

where n(Pi,,Pi,,..., P,,) is the number of elements of S possessingall of the


properties Pi,,P;,,...,P;,.The first expressionin brackets contains a term for each
property, the secondexpressionin brackets contains terms for all combinations of
two properties, the third expressioncontains terms for all combinations of three
properties,and so forth. (Hint: For each element of S determine the number of
times it is counted in the above expression. If an element has k of the

properties, t-
showit is counted
lrl + lpl- + (-l)ft
ltl ,i-.t. This
lrJ Itl lrJ
equals zeroby problem la(a).)

1 8 . The tower of Hanoi was a popular puzzle of the late nineteenth century. The
puzzle includes three pegs and eight rings of different sizes placed in order of
size, with the largest on the bottom, on one of the pegs. The goal of the puzzle is
to move all the rings, one at a time without ever placing a larger ring on top of a
smaller ring, from the first pbg to the second,using the third peg as an auxiliary
peg.
l8 The Integers

a) Use mathematicalinduction to show that the minimum number of movesto


transfer n rings, with the rules we have described,from one peg to another
is 2n - 1.

b) An ancient legend tells of the monks in a tower with 64 gold rings and 3
diamond pegs. They started moving the rings, one move per second, when
the world was created. When they finish transferring the rings to the second
peg, the world ends. How long will the world last?

19. Without multiplying all the terms, show that

il 6! 7!: l0! c) 16!: l4t 5t 2l


b) l0!:7! 5! 3! d ) 9 t - 7 13 ! 3 ! 2 ! .

20. Let an : (af a2l. ar-1!) - l, and on+t: af. a2t an_tl, where
or€ positiveintegers. Show that an*1!: al. a2t
o1,a2,...,etr-1 onl.
2 1 . F i n d a l l p o s i t i v ei n t e g e r sx , y , a n d z s u c h t h a t x t * y l : z!.

l.l Computer Projects

Write programs to do the following:

l. Find the sum of the terms of a geometric series.

2. Evaluate n !

3. Evaluate binomial coefficients.

4. Print out Pascal'striangle.

5. List the movesirr the Tower of Hanoi puzzle (see problem l8).

6. Expand (x*y)", where n is a positive integer, using the binomial theorem.

1.2 Divisibility
When an integer is divided by a secondnonzerointeger, the quotient may or
m ay not be an i n te g e r. F o r i n s ta n c e ,2 4 /8 : 3 i s an i nteger,w hi l e l 7/5:3.4
is not. This observationleads to the following definition.

Definition. If a and b are integers, we say that a divides b if there is an


integer c such that b : ac. lf a divides b, we also say that a is a divisor or
factor of b.
1.2 Divisibility t9

I f a d i v i d e sb w e w r i t e a l b , w h i l e i f a d o e s n o t d i v i d e b , w e w r i t e a t r U .

Example. The following examples illustrate the concept of divisibility of


i n t e g e r s1:3| 1 8 2-,5 | 9 0 ,t 7 l 2 8 g , e t r q q , l t r s o-,l | : 1 , a n d1 71 0 .

Example. The divisorsof 6 are +1, *2, +3, and +6. The divisorsof 17 are
tl and tI7. The divisors of 100 are +1, *2,+4, +5, +10,
+20, +25, +50, and + 100.

In subsequentsections,we will need some simple properties of divisibility.


We now state and prove these properties.

l b a n db l r , t h e n a l c .
1.3. If a,b,and c areintegerswitha
Proposition

Proof. Since a I b and b I c, there are integers e and f with ae : b and


bf : ,. Hence, bf : be)f : aGf) : c, and we concludethat a I c. a

Exa mple. S inc e 1l | 6 6 a n d 6 6 | tl a , P ro p o s i ti on1.3 tel l s us that 11 | 198.

P r o p o s i t i o n1 . 4 . l f a , b , m , a n d n a r e i n t e g e r sa, n d i f c l a a n d c l D , t h e n
c | (ma+nb).

Proof. Since c I a and c | 6, there are integers e and / such that a : ce and
b : c f . Henc e, m a * n b : m c e * n c f : c (me + nf). C onsequentl y,
w e see
th a t c | f ua+ nb) . E

Exa mple. S inc e 3l2 l a n d : I l l , Pro p o s i ti o n1 .4 tel l s us that


3 | 6 - z l - 3 . 3 3:) l o 5 - 9 9 : 6 .

The following theorem states an important fact about division.

The Divisionl$f$* If a and b are integers such that b > 0, then there
are unique integers q and r such that a : bq * r with 0 ( r < b.
In the equation given in the division algorithm, we call q the quotient and r
the remainder.
We note that a is divisible by b if and only if the remainder in the division
algorithm is zero. Before we prove the division algorithm, consider the
following examples.
20 The Integers

Example. If a-.133 and b:21, then Q:6 and r:7, since


133:21'6+7. L i k e w i s ei,f a : - 5 0 a n d b : 8 , t h e n q - - 7 and r:6,
s i n c e- 5 0 : 8 ( - 7 ) + 6.
For the proof of the division algorithm and for subsequent numerical
computations,we need to define a new function.

Definition. Let x be a real number. The greatest integer in x, denoted by


[x ], is the largest integer lessthan or equal to x.

Example. We have the following values for the greatest integer in


: 2,131: 3, andI-t.sl : -2.
x'. 12.21
The proposition below follows directly from the definition of the greatest
integer function.

Proposition 1.5. If x is a real number, then x-l < [x] ( x.


We can now prove the division algorithm. Note that in the proof we give
explicit formulae for the quotient and remainder in terms of the greatest
integer function.

Proof. Let q:la/bl a n d r : a - b l a / b l . C l e a r l ya : b q * r . T o s h o w


that the remainder r satisfies the appropriate inequality, note that from
Proposition1.5, it follows that

G/b)-l < ta/bl 4a/b.

We multiply this inequality by b, to obtain

a - b < btalbl 4 a.

Multiplying by -1, and reversingthe inequality,we find that


-a(-b[a/bl<b-a.

By adding e, we seethat
0 ( r - a - bla/bl < n.

To show that the quotient q and the remainder r are unique, assume that
w e h a v e t w o e q u a t i o n sa : b q r * r r a n d a : b q z * r r , w i t h 0 ( r r ( b a n d
0 ( rz < b. By subtracting the secondof these from the first, we find that
1.2 Divisibility 2l

0:bQt-qr)+(r;r2)

Hence. we seethat
rz - rr: b(qt-qr).

Th i s tells us t hat D d i v i d e s rz - rr. Si n c e 0 ( rr I b and 0 ( rz ( b, w e


have -b < rz- rr 1b. This shows that b can divide rz- 11 only if
r z - 1 1 : 0 , o r , i n o t h e r w o r d s ,i f 1 1 : 1 2 . S i n c e b q t + r t : b Q z * 1 2 a n d
rt: 1 2 we als o s ee th a t Qr: Qz . T h i s s h o w s th at the quoti ent q and the
remainder r are unique. tr

E x a m p l e .L e t a : 1 0 2 8 a n d b : 3 4 . Then a:bq*r with 0(r <b,


w h e r e q : t t 0 2 8 / 3 4 1 : 3 0 a n d r : 1 0 2 8 - 1 1 0 2 8 / 3 4 1 . 3 4 : 1 0 2 8- 3 0 . 3 4 : 8 .
W i t h a : - 3 8 0 a n d b : 7 5 , w e h a v ea : b q * r w i t h 0 ( r < b , w h e r e
q : [-380/ 751 : - 6a n d r : -3 8 0 - t-3 8 0 /7 5 1 : -380 - (-6)75 : 70.
Given a positive integer d, we can classify integers according to their
remainders when divided by d. For example, with d : 2, we see from the
division algorithm that every integer when divided by 2leaves a remainder of
either 0 or l. If the remainder when n is divided by 2 is 0, then r : 2k for
some positive integer k, and we say n is even, while if the remainder when n
i s d i vi dedby 2 is l, th e n n :2 k * I fo r s o mei n tegerk,and w e say n i sodd.

Similarly, when d : 4, we see from the division algorithm that when an


integer n is divided by 4, the remainder is either 0,1,2, or 3. Hence, every
i n te g e r is of t he f orm 4 k ,4 k + l ,4 k * 2 , o r 4 k + 3, w here k i s a posi ti ve
integer.
We will pursue these matters further in Chapter 3.

1.2 Problems
l. S h o wt h a t3 l g g , s I t + S , 7 l 3 4 3 ,a n d8 8 8| 0 .
2. Decidewhich of the followingintegersare divisibleby 22
il0 d) r92s44
b) 444 e) -325r6
c) 1716 f) -195518.
22 The Integers

3. Find the quotient and remainder in the division algorithm with divisor 17 and
dividend

a) loo c) -44
b) 28e d) -100.

4. What can you conclude if a and b are nonzero integers such that a I b and
bla?

5. Show that if a, b, c, and d are integers with a and c nonzero such that a I b
and c I d, then ac I bd.

6 . A r e t h e r e i n t e g e ras, b , a n d c s u c h t h a t a l b c , b u t a I b anda I c).


7 . Show that if a, b,and c l0 a r e i n t e g e r s t, h e n a I t i f a n d o n l y i f a c I b c .
8 . Show that if a and b are positive integers and a I D, then a ( D.
9 . Give another proof of the division algorithm by using the well-ordering property.
(Hint: When dividing a by b, take as the remainder the least positive integer in
the set of integersa-qb.)

1 0 . Show that if a and b are odd positive integers, then there are integers s and ,
s u c ht h a t a : b s * / , w h e r eI i s o d d a n d l r l < n .
When the integer a is divided by the interger b where b > 0, the division
algorithm gives a quotient of q and a remainder of r. Show that if 6 ,f a, when
-a is divided by b, the division algorithm gives a quotient of -(q*l) and a
remainder of b - r, while if 6 | a, the quotient is -q and the remainder is zero.

1 2 . Show that if a, b, and c are integers with b ) 0 and c ) 0, such that when a
is divided by b the quotient is q and the remainder is r, and when q is divided
by c the quotient is / and the remainder is s, then when a is divided by bc, the
quotient is I and the remainder is bs * r.

1 3 . il Extend the division algorithm by allowing negative divisors. In particular,


show that whenever a and b # 0 are integers, there are integers q and r
such that a : bq * r, where 0 ( r < lAl .

b) Find the remainderwhen 17 is divided by -7.

1 4 . Show that if a and D are positive integers, then there are integers q,r and
e : ! . 1 s u c ht h a t a : bq * er where-b/2 <er4 b/2.

1 5 . S h o w t h a t i f a a n d b a r e r e a l n u m b e r s ,t h e n l a + b l 2 l a ] + [r].

1 6 . Show that if a and b are positive real numbers, then labl 2 Laltbl .
What is the corresponding inequality when both a and b are negative? When
one is negative and the other positive?
1.2 Divisibilitv 23

17. What is the value of [a ] + l-a I when a is a real number?

18. Show that if a is a real number then

a) -I-a I is the least integer greater than or equal to a.


b) la + %l is the integer nearest to a (when there are two integers equidistant
from a, it is the larger of the two).

19. Show that if n is an integer and x is a real number, then [x*n] : [xl + n .

20. Show that if m and n \ 0 are integers, then


(r r
I 1I1 | if m : kn - I for someintegerk.
| * + r 1 . J L J'
I n_ i : l l I
I I llyl*tif m:kn-lforsomeintegerk.
ILnl
21. Show that the integer n is even if and only if n - 2ln /21 : 0.

22. Show that if a is a real number, then [a ] + Ia + %l : l2al .

23. a) Show that the number of positive integers less than or equal to x that are
divisible by the positive integer d is given by [x/dl.

b) Find the number of positive integers not exceeding 1000 that are divisible by
5 , b y 2 5 , b y 1 2 5 ,a n d b y 6 2 5 .

c) How many integers between 100 and 1000 are divisible by 7? by 49'l

24. To mail a letter in the U.S.A. it costs 20 cents for the first ounce and l8 cents
for each additional ounce or fraction thereof. Find a formula involving the
greatest integer function for the cost of mailing a letter. Could it possibly cost
S 1.08 or ,$I .28 to mail a letter?
25. Show that if a is an integer, then 3 divides a3-a

26. Show that the sum of two even or of two odd integers is even, while the sum of
an odd and an even integer is odd.

27. Show that the product of two odd integers is odd, while the product of two
integers is even if either of the integers is even.

28. Show that the product of two integers of the form 4ft * I is again of this form,
while the product of two integers of the form 4k * 3 is of the form 4ft * L

29. Show that the square of every odd integer is of the form 8k + l.
24 The Integers

30. Show that the fourth power of every odd integer is of the form l6k + l.

31. Show that the product of two integers of the form 6k * 5 is of the form 6k * L

32. Show that the product of any three consecutiveintegers is divisible by 6.

33. Let n be a positive integer. We define


f

ln/2 if n is even
T(n) :
1Qn*D/z if n is odd.

We then form the sequence obtained by iterating T:


n , T ( n ) , T ( T Q ) ) , f ( f ( f ( n ) ) ) , . . . . F o r i n s t a n c e ,s t a r t i n g w i t h n : 7 w e h a v e
7 , 1 1 , 1 7 , 2 6 , 1 3 , 2 0 , 1 0 , 5 , 8 , 4 , 2 , 1 , 2 , 1 , 2. , 1A
... well-known conjecture,sometimes
called the Collatz coniecture, assertsthat the sequenceobtained by iterating Z
always reachesthe integerI no matter which positive integer n begins the sequence.

a) Find the sequenceobtainedby iterating Z starting with n :29.

b) Show that the sequenceobtained by iterating Z starting with n: (2k-l)/3,


where k is an even positive integer, k > l, always reachesthe integer l.

1.2 Computer Projects

Write programs to do the following:

l Decide whether an integer is divisible by a given integer.

2. Find the quotient and remainder in the division algorithm.

3. Find the quotient, remainder, and sign in the modified division algorithm given in
problem 14.

4. I n v e s t i g a t et h e s e q u e n c en , T ( n ) , T ( T h ) ) , f (rQ ( n ) ) ) , . . . d e f i n e di n p r o b l e m
33.

1.3 Representations
of Integers
The conventionalmanner of expressingnumbersis by decimal notation. We
write out numbers using digits to representmultiples of powers of ten. For
instance,when we write the integer 34765,we mea;r
3 . 1 0 4+ 4 . 1 0 3+ 7 . 1 0 2+ 6 . 1 0 1+ 5 . 1 0 0 .

There is no particular reasonfor the use of ten as the base of notation,other


than the fact that we have ten fingers. Other civilizations have used different
of Integers
1.3 Representations 25

bases,including the Babylonians,who used base sixty , and the Mayans, who
used base twenty Electronic computers use two as a base for internal
representationof integers,and either eight or sixteen for display purposes.
We now show that every positive integer greater than one may be used as a
base.

Theorem 1.3. Let b be a positive integer with b > l. Then every positive
integer n can be written uniquely in the form
n : a k b k * a p - 1 b k - rt * a1b I oo,

w h e r e a; is an int eg e rw i th 0 ( o ; < b -l fo r,/ :0, 1,..., k and the i ni ti al


coefficientak I O.

Proof . We obtain an expressionof the desired type by successivelyapplying


the division algorithm in the following way. We first divide n by b to obtain
n:beo*oo, 0(ao<b-1.

Then we divide qoby b to find that

eo:bq1ta6 0(ar(6-t.

We continue this processto obtain

Qt: bq2t a2, 0 ( a2 ( b-1,


qr= bq3l a3, 0 ( ar ( b-1,

Q k - z: b q * - r * a k - r , 0 ( a 1 - 1 ( b - 1 ,
Qk-t: b.0 * ap, 0 ( a1 ( b-t.

The last step of the processoccurs when a quotient of 0 is obtained. This is


guaranteedto occur, becausethe sequenceof quotients satisfies

n ) qo) qr) qz> "'> 0,

and any decreasing sequence of nonnegative integers must eventually


terminate with a term equaling 0.
26 The Integers

From the first equation above we find that

n: beo* ao.

We next replace {6 using the secondequation, to obtain

n : b(bqfta1) + as : bzqrI a1b I as,

Successively
substituting for qr, Q2,..., Qk_r,we have

n: b 3 q z + a 2 b 2* a 1 b * o r ,

: =i: ri::,-'**"::,t{,-'..**olr'u**ol'
: a t b k + a 1 r - 1 b k -*r t aft * ao.

w her e 0 ( a; < b -l fo r 7 : 0 ,1 ,...,ka n d a * I 0, si nceek : 4r-r i s the l ast


nonzero quotient. Consequently,we have found an expansion of the desired
type.
To see that the expansion is unique, assume that we have two such
expansionsequal to n, i.e.

n : e k b k + a 1 r - y b k - *t t a1b * ao
: c * b k * c 1 r-1 b k -r* * cft * ro,

where 0 ( ar (b and 0 ( c1(b (and if necessarywe add initial terms with


zero coefficients to have the number of terms agree). Subtracting one
expansionfrom the other, we have
(ar,-c)bk +(o,,-r-c1,-)bk-t * *(a;cr)b + (as-ca):0.

If the two expansionsare different, there is a smallest integer j, O ( < k,


"l
such that ai # ci. Hence,
.f
br + * (ai+rci+r)b * G1-c1)] : o,
l(a*-c*)b(-r
so that

Gr,-c)bk-i + + (a1+rci+)b r (ai-c1) : O.


1.3 Representationsof Integers 27

Solving for ai-c; we obtain

aj- c j: (c rr-a r)b k -j + * (c 7+ r-ai + )b

: bl(c1,-a1)bk-j-t + * (c7+r-or*,)
].

Hence, we see that


bl G 1 -c 1 ).

But since 0 ( a; < b and 0 ( c; < b, we know that -b < ai-c1 I b.


Consequently, b I h1-c) implies that ej : cj. This contradicts the
assumptionthat the two expansionsare different. We concludethat our base
6 expansionof n is unique. !
For b - 2 . we see from Theorem 1.3 that the following corollary holds.

Corollary 1.1. Every positive integer may be represented as the sum of


distinct powersof two.

Proof. Let n be a positive integer. From Theorem 1.3 with b : 2, we know


t h a t n : a t r T k * a 1 r - 1 2 k - t* + a Q * a s w h e r e e a c h a ii s e i t h e r 0 o r 1 .
Hence, every positive integer is the sum of distinct powersof 2. tr
In the expansionsdescribedin Theorem 1.3, b is called the base or radix of
the expansion. We call base l0 notation, our conventionalway of writing
integers, decimal notation. Base 2 expansionsare called binary expansions,
base 8 expansionsare called octal expansions,and base 16 expansionsare
called hexadecimal, or hex for short, expansions. The coefficients ai are
called the digits of the expansion. Binary digits are called bits (binary
digils) in computer terminology.
To distinguish representationsof integers with different bases, we use a
special notation. We write (apapa...aps) 6 to represent the expansion
a*bklapabk-rl taft*ao.

Example. To illustrate base b notation, note that Q3Ot : 2.72+ 3.7 + 6


a n d ( 1 0 0 1 0 0 1 1 :) 2 1 . 2 7+ 1 . 2 4+ 1 . 2 r+ 1 .
Note that the proof of Theorem 1.3 gives us a method of finding the base b
expansion of a given positive integer. We simply perform the division
algorithm successively,replacing the dividend each time with the quotient, and
28 The Integers

stop when we come to a quotient which is zero. We then read up the list of
remaindersto find the base b expansion.

Example. To find the base 2 expansionof 1864, we use the division algorithm
successively:

1 8 6 4: 2 . 9 3 2 + 0 ,
932:2'466 +0,
466:2'233 +0
233-2'116+1,
1 1 6: 2 ' 5 8 + 0 ,
58:2'29 +0,
29:2'14 +1,
14:2'7 +0,
7 : 2'3 + 1,
3 : 2'l + l,
| : 2'O + 1.

To obtain the base 2 expansionof 1984, we simply take the remaindersof


t h e s ed i v i s i o n s .T h i s s h o w st h a t ( 1 8 6 4 ) r o : ( 1 1 1 0 1 0 0 1 0 0 0 ) 2 .

Computers represent numbers internally by using a series of "switches"


which may be either "on" or "off". (This may be done mechanically using
magnetic tape, electrical switches, or by other means.) Hence, we have two
possiblestates for each switch. We can use "on" to represent the digit I and
"off" to representthe digit 0. This is why computers use binary expansionsto
representintegers internally.
Computers use base 8 or base 16 for display purposes. In base 16, or
hexadecimal, notation there are l6 digits, usually denoted by
7 9 ,A,8 ,,C ,D ,,Ea n d F . T h e l e tters A ,B ,C ,D ,E , and F are
0 ,1, 2, 3, 4, 5, 6,, 8,
used to representthe digits that correspondto 10,11,12,13,14 and l5 (written
in decimal notation). We give the following example to show how to convert
from hexadecimalnotation to decimal notation.

Example. To convert (A35B0F) 16we write


( e l s n o r ) r e : 1 0 . 1 6 s + 3 ' 1 6 4+ 5 ' 1 6 3+ l l ' r c z + 0 ' 1 6 + 1 5
: ( t o7o5 679)rc.
1.3 Representationsof Integers 29

A simple conversionis possible between binary and hexadecimal notation.


We can write each hex digit as a block of four binary digits according to the
correspondencegiven in T a b l e l . l .

Hex Binary Hex Binary


Digit Digits Digit Digits

0 0000 8 r000
I 0001 9 1001
2 0010 A 1010
3 0 0 1l B 1011
4 0100 C l 100
5 0101 D I l0l
6 0110 E 1110
7 0l l1 F llll

Table1.1. Conversion
from hex digits to blocksof binarydigits.

Example. An example of conversionfrom hex to binary is (zFBrrc:


(tOt t 1110110011)2 .E a c h h e x d i g i t i s c o n v e rt edto a bl ock of four bi nary
digits (the initial zeros in the initial block (OOIO)2correspondingto the digit
(2) rc are omitted).

To convert from binary to hex, consider(t t t tOl I I101001)2. We break this


into blocks of four starting from the right. The blocks are, from right to left,
1 0 0 1, 1110, 1101,an d 0 0 1 1 (w e a d d th e i n i ti a l z eros). Transl ati ngeach bl ock
to hex, we obtain GOng)ru.
We note that a conversionbetween two different basesis as easy as binary
hex conversion,wheneverone of the basesis a power of the other.

1.3 Problems
l. Convert (1999)1sfrom decimal to base 7 notation. Convert (6tOS)t from base 7
to decimal notation.

2. Convert (tOtOOtOOO),from binary to decimal notation and (tgg+),0 from


decimal to binary notation.
30 The Integers

3 . c o n v e r t ( 1 0 0 0 1 II l 0 l 0 l ) 2 a n d ( l I 1 0 1 0 0 1 1 1 0 ) 2f r o m b i n a r y t o h e x a d e c i m a l .
4 . convert (ABCDEF)rc, @nrecnD)to, and (9A08)rc from hexadecimal to
binary.

5 . Explain why we really are using base 1000 notation when we break large decimal
integers into blocks of three digits, separatedby commas.

6 . a) Show that if D is a negative integer less than -1, then every integer n can
be uniquer';:.])::'::;'

. * a 1 b* oo,

where a1, I 0 and O <a, < lb I for ./ : 0,1,2,...,k. We write


n : (apa1,-r...ata6)6,just as we do for positivebases.

b) Find the decimal representationof (tOtOOt)-2 and OZOTD-r.

c) Find the base-2 representations


of the decimal numbers-7,-17, and 61.
7 . Show that any weight not exceeding 2k-l may be measured using weights of
1,2,22,...,2ft-1,
when all the weights are placed in one pan.

8 . Show that every integer can be uniquely representedin the form


ep3k*ep-.3k-t* *efiles

where €i : -1,0, or I for ,/:0,1 ,2, ..., k. This expansion is called a


balanced ternary expansion.

9. Use problem 8 to show that any weight not exceeding $k -t) /Z may be
m e a s u r e du s i n g w e i g h t so f 1 , 3 , 3 ' , . . . , 3 f t - 1 , w h e n t h e w e i g h t sm a y b e p l a c e di n
either pan.

r0. Explain how to convert from base 3 to base 9 notation, and from base 9 to base 3
notation.

ll. Explain how to convert from base r to base rn notation, and from base rn
notation to base r notation, when r ) I and n are positive integers.

1 2 . Show that if r: ( a * a * - 1 . . . a p s ) 6 , t h e n t h e q u o t i e n t a n d r e m a i n d e rw h e n n i s
divided by bi are q : (apa1,-1...a)6and, : (aj-r...apo)t, respectively.

1 3 . If the base b expansion of n is n : (apa1,-1...aps)6,what is the base b


expansionof b^ n"l

14. A Cantor expansion of a positive integer n is a sum

fl:ommt * a^a(m-l)! + * a 2 2 l* a 1 l !
1.3 Representationsof Integers 3t

where each ai is an integer with 0 ( a; < i .

a) Find Cantor expansionsof 14, 56, and 384.

b) Show that every positive integer has a unique Cantor expansion.

15. The Chinese game of nim is played as follows. There are a number of piles of
matches, each containing an arbitrary number of matches at the start of the
game. A move consistsof a player removing one or more matches from one of
the piles. The players take turns, with the player removing the last match
winning the game.

A winning position is an arrangement of matches in piles so that if a player can


move to this position, then, no matter what the second player does, the first
player can continue to play in a way that will win the gom€; An example is the
position where there are two piles each containing one match; this is a winning
position, becausethe second player must remove a match leaving the first player
the opportunity to win by removing the last match.

a) Show that the position where there are two piles, each with two matches, is
a winning position.

b) For each arrangement of matches into piles, write the number of matches in
each pile in binary notation, and then line up the digits of these numbers
into columns (adding initial zeroes if necessaryto some of the numbers).
Show that a position is a winning one if and only if the number of ones in
each column is even (Example: Three piles of 3, 4, and 7 give
0ll
llt
100
where each column has exactly two ones).

16. Let a be an integer with a four-digit decimal expansion,with not all digits the
same. Let a' be the integer with a decimal expansion obtained by writing the
digits of a in descending order, and let a" be the integer with a decimal
expansion obtained by writing the digits of a in ascending order. Define
T ( a ) : a ' - a " . F o r i n s t a n c ef,( 2 3 1 8 ) 8731 1378 : 7358.
a) Show that the only integer with a four-digit decimal expansion with not all
d i g i t s t h e s a m es u c h t h a t T ( a ) : a i s a : 6 1 7 4 .

b) Show that if a is a positive integer with a four-digit decimal expansionwith


not all digits the same, then the sequence a, T (d, f (f G)) ,
T'QQ(a))),..., obtained by iterating T, eventually reaches the integer
6174. Becauseof this property, 6174 is called Kaprekar's constant.
32 The Integers

17. Let b be a positive integer and let a be an integer with a four-digit base b
expansion,with not all digits the same. Define TtG) : a'- a", where a'is the
integer with base D expansion obtained by writing the base 6 digits of a in
descending order, and let d " is the integer with base 6 expansion obtained by
writing the base b digits of a in ascendingorder.

il Let b : 5. Find the unique integer a6 with a four-digit base 5 expansion


such that TsGl : ao. Show that this integer aq is a Kaprekar constant for
t h e b a s e 5 , i . e . , a , T ( a ) , r ( f b ) ) , f ( f Q ( a ) ) ) , . . . e v e n t u a l l yr e a c h e s
40, whenever a is an integer which a four-digit base 5 expansionwith not all
digits the same.

b) Show that no Kaprekar constant exists for the base 6.

1.3 Computer Projects

Write programs to do the following:

l. Find the binary expansion of an integer from the decimal expansion of this
integer and vice versa.

2. Convert from base 61 notation to base b2 notation, where D1 and b2are arbitrary
positive integers greater than one.

3. Convert from binary notation to hexadecimal notation and vice versa.

4. Find the base (-2) notation of an integer from its decimal notation (see problem
6).

5. Find the balanced ternary expansion of an integer from its decimal expansion
(see problem 8).

6. Find the Cantor expansionof an integer from its decimal expansion (see problem
14).

7. Play a winning strategy in the game of nim (see problem l5).

8. F i n d t h e s e q u e n c ea , T ( a ) , T ( T f u ) ) , r ( r O Q ) ) ) , . . . definedin problem 16,


where a is a positive integer, to discoverhow many iterations are neededto reach
6174.

9. Let b be a positive integer. Find the Kaprekar constant to the base b, when it
exists (see problem 17).
of Integers
1.3 Representations 33

1.4 Computer Operationswith Integers


We have mentioned that computers internally representnumbers using bits,
or binary digits. Computers have a built-in limit on the size of integers that
can be used in machine arithmetic. This upper limit is called the word size,
which we denote by w. The word size is usually a power of 2, such as 235,
although sometimesthe word size is a power of 10.
To do arithmetic with integers larger than the word size, it is necessaryto
devote more than one word to each integer. To store an integer n ) l4/, we
expressn in base w notation, and for each digit of this_expansionwe use one
computer word. For instance, if the word size is 23s, using ten computer
words we can store integers as large u, 23s0-1, since integers less than 2350
have no more than ten digits in their base 235expansions. Also note that to
find the base 235expansionof an integer, we need only group together blocks
of 35 bits.

The first step in discussing computer arithmetic with large integers is to


describehow the basic arithmetic operationsare methodically performed.
We will describe the classical methods for performing the basic arithmetic
operations with integers in base r notation where r ) | is an integer. These
methodsare examplesof algorithms.

Definition. An algorithm is a specified set of rules for obtaining a desired


result from a set of input.
We will describe algorithms for performing addition, subtraction, and
multiplication of two n-digit integers a : (an4on-z...egi, and
b : (bn- 1br - z . . . br b o )r,w h e re i n i ti a l d i g i ts o f z e ro are added i f necessaryto
make both expansionsthe same length. The algorithms described are used
both for binary arithmetic with integers less than the word size of a computer,
and for multiple precision arithmetic with integers larger than the word size
w, using lr as the base.
We first discuss the algorithm for addition. When we add a and b, we
obtain the sum

a I b : 5 a i r t+ ' i u , r t : 5 G i + b 1 ) r i .
j-o j-0 j:o

To find the base r expansion of the a * b, first note that by the division
algorithm, there are integers Cs and ss such that
34 The Integers

ao* bs: Csr * r0,0 ( so 1 r.

Because as and bo are positive integers not exceeding r, we know that


0 ( ao * bo( 2 r - 2 , s o th a t c o :0 o r l ;h ere c6 i s the cany to the next
place. Next, we find that there are integersc1 and s1 such that

ar * br t Co: C{ t rr,0 ( s1 ( r.

Since0 ( art br * Co ( 2r - 1, we know that Cr:0or l. proceeding


i n d u c t i v e l y , w e f i n d i n t e g e r s Ca; n d s ; f o r 1 ( i ( n - I b y

ai * b; * Ci-r: Crr trr, 0 ( s; ( r,

wit h C; : 0 or 1 . F i n a l l y , w e l e t s r: C n ; , si nce the sum of tw o i ntegers


with n digits has n * I digits when there is a carry in the n th place. We
co nc ludet hat t he b a s er e x p a n s i o nfo r th e s u m i s a * b: (srsn_,...J1.ss)7
.
When performing base r addition by hand, we can use the same familiar
technique as is used in decimal addition.

E x a m p l e . T o a d d ( 1 1 0 1 ) 2a n d ( l 0 l l ) 2 w e w r i t e

II
1l0l
+1001
10110

where we have indicated carries by I's in italics written above the appropriate
column. We found the binary digits of the sum by noting that I * I :
l'2+ 0,0+0+ 1:0'2 * 1, I +0f 0: O'2+ l,and 1+ l:1.2 *0.
We now turn our attention to subtraction. We consider

a - b :'; airi -'i u,rt: 5 Gi - b)ri ,


j-o j-0 j-0

where we assumethat a ) b. Note that by the division algorithm, there are


integers ^Bsand ds such that

os- bo: 86r * dg, 0 ( do ( r,

and since as and bs are positive integers less than r, we have


1.4 Computer Operationswith Integers 35

-(r-l)<as-bo(r-1.

W h e n a o - b o ) 0 , w e h a v e , 8 6 : 0 . O t h e r w i s ew, h e n a s - b o 1 0 , w e h a v e
Bo: - 1;Bo is the borrow from the next place of the baser expansionof a.
We use the division algorithm again to find integersB1 and d1 such that
a1-bt+ Bo: B{ * dr. 0 < d1 1 r.

From this equation, we see that the borrow B r : 0 as l o n g a s a 1 - b t + B o


- br * B o
> 0 , a n d B t : - l o t h e r w i s e ,s i n c e - r ( a r (r-l.We
proceedinductively to find integers B; and d;, such that
ai - btf Bi-r : Bir t di. 0 ( di 1 r

w i t h B ; : 0 o r - 1 , f o r I < t < n - 2. We seethat Bn4: 0, sincea ) b.


We can concludethat
a - b : (dnadn-2...d1ds),.

When performing base r subtraction by hand, we use the same familiar


technique as is used in decimal subtraction.

Example. To subtract ( t o t t o ) 2f r o m ( t t o t l ) 2 , w e h a v e
-t
llotl
-10110
101

where the -l in italics above a column indicates a borrow. We found the


binary digits of the difference by noting that 1 - 0 : 0'2 * l,
1-l:0'2*0, 0-l:-1'2+1, l-0-l: 0'2+0, and 1-l:
0'2+ 0.
Before discussing multiplication, we describe shifting. To multiply
(on-r...aps)7 by r^ , we need only shift the expansion left m places,
appending the expansionwith m zero digits.

Example. To multiply (tOtt01)2 by 2s, we shift the digits to the left five
placesand appendthe expansionwith five zeros,obtaining (10110100000)2.
36 The Integers

To deal with multiplication, we first discussthe multiplication of an n-place


i n t eger by a on e -d i g i t i n te g e r. T o m u l ti p l y (an_1...ori ;, by (i l ,, w e fi rst
note that

oob:Qor*po,0(ps(r,

a nd 0 ( qo ( r - l , s i n c e0 ( a o b ( (r-1 )2 . N ext, w e have

aft+Qo:Qf *pr,0(pt1t,

and 0 ( qt ( r-1 . In g e n e ra l ,w e h a v e
a;b * 7i-r: Qir I pi, 0 ( p; -< r

and 0 ( gr ( r - 1. Furthermore, we have pn: Qn_r. This yields


(o r - 1. . . ar , o), ( b ) , : (p n p n -r...pg .o ),.

To perform a multiplication of two n-place integers we write


( n-t ) n-t
ab:al>biril:)Gb)ri.
l i -r ) i -o

For each -/, we first multiply a by the digit b;, then shift to the left 7 places,
and finally add all of the n integers we have obtained to find the product.
When multiplying two integers with base r expansions,we use the familiar
method of multiplying decimal integers by hand.

Ex am ple. T o m u l ti p l y (l l 0 l )2 a n d (t t tO )2 w e w ri te

ll0l
x1110
0000
I l0l
1l0l
l10l
l0ll01l 0

Note that we first multiplied (1101)2 by each digit of (t t 10)t, shifting each
time by the appropriate number of places, and then we added the appropriate
integers to find our product.
1.4 Computer Operations with Integers 31

We now discuss integer division. We wish to find the quotient q in the


division algorithm
a:bq + R, 0 < R < b.

If the base r expansionof q is q : (Qn-rQn-2...Q


1 4 o,) , then we have
( n-r
a-b l> eiril +R,0<R <b.
[r-o

To determine the first digit Qrq of q, notice that

a - bqn-1vn-t
: uf'i qjri)+ R.
U-o )
The right-hand side of this equation is not only positive,but also it is less than
brn-t, since 2 qiri g rn-l-l. Therefore,we know that
j-0

0 ( a - bqn-(n-l < brn-t.

This tells us that O: Tt, -tn.'l


(L
4v n n { . t " ' , Qn-r: la/brn-rl'
t-"rf

We can obtain Qn-r by successivelysubtracting br"-l from a until a negative


result is obtained, and then qn-1is one less than the number of subtractions.

To find the other digits of q,, we define the sequenceof partial remainders
Ri by

Ro: a

and

Ri:Ri-r - bqn-trn-i

f o r i : 1 , 2 , . . . ,n . B y mathematical induction, we show that


(n -i -t I
(r.s) Ri: qirtlb+R.
| >
lj-0 )

For i : 0, this is clearly correct, since R0 : a : qb + R. Now assumethat


38 The Integers

Rft:

Then

Rt+r : Rft - bqn-*-rrn-k-l


'l
(n-k-t .
: qirilb+R-bqn-*-rvn-k-l
I U
l. .r-o )
fn-(k+r)-r .l
:| > qi"lb+R'
Ij-0)

e s t a b l i s h i n( 1g . 5 ) .
F r o m ( t . S ) , w e s e e t h a t 0 ( R i < r n - i b , f o r i : 1 , 2 , . . . ,f l , s i n c e
n-i -l

i-0
O ( Ri < rn-tb, we see that the digit qn-i is given by lRi-r/brn-il and can
be obtained by successivelysubtracting brn-t from Ri-1 until a negative result
is obtained,and then qn-; is one lessthan the number of subtractions. This is
how we find the digits of q.

E x a m p l e .T o d i v i d e( t t t O l ) 2 b y ( t t t ) 2 , w e l e t q : ( q r q r q i r . W e s u b t r a c t
Z2( t t l) z : ( t t t O O), o n c e fro m (t t tO t)z to obtai n (l )2, and once more to
o b t a i na n e g a t i v er e s u l t s, o t h a t Q 2 : l . N o w R l : ( t t t O l ) t - ( t t t 0 0 ) t :
(1)2. We find that ql:0, s i n c eR 1 - 2 ( 1 l l ) 2 i s l e s st h a n z e r o ,a n d l i k e w i s e
Qz : 0. Henc e t h e q u o ti e n t o f th e d i v i s i o ni s (1 00)2and the remai nderi s (l )2

We will be interested in discussinghow long it takes a computer to perform


calculations. We will measure the amount of time needed in terms of
bit operations. By a bit operation we mean the addition, subtraction, or
multiplication of two binary digits, the division of a two-bit integer by one-bit,
or the shifting of a binary integer one place. When we describethe number of
bit operations needed to perform an algorithm, we are describing the
computational complexity of this algorithm.
In describing the number of bit operations needed to perforrn calculations
we will use big-O notation.
1.4 ComputerOperationswith Integers 39

Definition. If f and g are functions taking positive values, defined for all x in
a set S, then we say f is OQ) if there is a positive constant K such that
f G) < K g( x ) f or a l l x i n th e s e t S .

Proposition 1.6. If / is OQ) and c is a positiveconstant,then cf is Ok).

Proof . If / is Ok), then there is a constantK such that f G) < Kg(x) for
all x under consideration. Hence cf G) < GK)gG). Therefore, y' is
oQ). n

P r o p o s i t i o1n. 7 .l f f t i s O ( g r ) a n d f 2 i s O k z ) , t h e n" f t + - f z i s O Q f t g 2 )
andfJzisoQe).

Proof . If / is OQr) and f2 is Okz), then there are constantsK1 and K2


su ch t hat - f , ( *) < ,< 1 g 1 (x ) a n d " f z (x ) 1 K2g2(x) for al l x under
consideration. Hence

f 1G) +f2G) ( Krsr(x) + x2g2k)


( Kkr(x) + sz?))

where K is the maximum of K1 and K2. Hencef r + -f zis Ok, + gz).


Also

-f tk)f z(.x) ( Krsr G) K2s2G)


: (KrK2)kt?)g2(x)),

so th at " f f z is 0( 96 ). tr

C o rollar y 1. 2. I f / 1 a n d f 2 a re O G), th e n -f r + -f zi s Ok).

Proof . Proposition 1.7 tells us that


"f t + f z is O QS). But if
+
f t "fz ( K Q s ) , t h e nf t + ( (z x )g , s o th at -f r + .f zi s Ok). a
" fz
Using the big-O notation we can see that to add or subtract two r-bit
integers takes Ofu) bit operations,while to multiply two n-bit integers in the
conventionalway takes OGz) bit operations(see problems 16 and 17 at the
end of this section). Surprisingly, there are faster algorithms for multiplying
large integers. To develop one such algorithm, we first consider the
multiplication of two 2n-bit integers, say a : (a2n4a2n_2...eflo)z and
b : ( b 2 , 6 b , 2 n - 2 . . . b f t iW
2 .e w r i t e a : 2 n A t f 4 6 a n d b : 2 n B r t B s , w h e r e
-l
40 The Integers

A t : ( a 2 r - 1 a 2 n * 2 . . . a 1 7 1 1 eA1o7: ) 2 (, a n - 1 a n - 2 . . . a p g ) 2B, t : ( b 2 n - f t 2 r - z . . . b n + t
br)2, and B0 : (br-t bn-z...brbiz. We will use the identity
(t.e) a b : ( 2 2 , + 2 , ) A r B r r 2 n( A r A i ( a o - n r ) + (2,+l)AoB0.

To find the product of a and 6 using (t.0), requires that we perform three
mu lt iplic at ions o f n -b i t i n te g e rs (n a me l y A r B r (A , - A d(B o- B r), and
AsBs), as well as a number of additions and shifts. If we let M(n) denote the
number of bit operations needed to multiply two n -bit integers, we find from
(t.0) t t r at

(r.z) M (2n) < ru h) + Cn.

where C is a constant, since each of the three multiplications of n -bit integers


takes M (n) bit operations,while the number of additions and shifts neededto
compute a'b via (t.0) does not depend on n, and each of these operations
takes O (n) bit operations.
From (t.Z), using mathematical induction, we can show that
(1.8) a(zk) ( c(3k -2k),

where c is the maximum of the quantities M Q) and C (the constant in


(t.Z)). To carry out the induction argument, we first note that with k: l,
we have MQ) ( c(3t -2t) : c, sincec is the maximum of M(2) and C.
As the induction hypothesis,we assumethat
MQk) ( c (3 ft - 2 k).

Then, us ing ( 1. 7), w e h a v e

M (z k + t) ( 3 u (z k ) + czk
( 3c (lt - 2k) + c2k
( c a k + t_ c . 3 . 2 k* c 2 k
( c ( 3 f t + l- zk+t).

This establishesthat (1.8) is valid for all positive integers ft.

Using inequality (t.8), we can prove the following theorem.

Theorem 1.4. Multiplication of two n-bit integers can be performed using


O(nto9'3) bit operations. (Note: log23 is approximately 1.585, which is
1.4 ComputerOperationswith Integers 4l

considerably less than the exponent 2 that occurs in the estimate of the
number of bit operations needed for the conventional multiplication
algorithm.)

Proof . From (t.8) we have


M h) : M (ztos'n)( lzlttloerl+t;

< , (3ttot'nl+t_rltoe'nl+t;
( 3 c .rl l o g Irn( 3 c .3 l o sr,:3rnto93

(since 3lo8'n: ,'ot").

Hence, Mh) : glnroe'3l. tr

We now state, without proof, two pertinent theorems. Proofs may be found
in Knuth [50] or Kronsjii tSgl.

Theorem 1.5. Given a positive number e ) 0, there is an algorithm for


multiplication of two n-bit integersusing O(nr+') bit operations.

Note that Theorem 1.4 is a specialcaseof Theorem 1.5 with e : log23- l,


which is approximately0.585.

Theorem 1.6. There is an algorithm to multiply two n-bit integers using


O(n log2n log2log2n)bit operations.
Since log2n and log2log2nare much smaller than n' for large numbers n,
Theorem 1.6 is an improvement over Theorem 1.5. Although we know that
M h) : O (n log2n log2log2n), for simplicity we will use the obvious fact that
M fu) : O (n2) in our subsequentdiscussions.
The conventionalalgorithm described above performs a division of a 2n-bit
integer by an n-bit integer with O(n2) bit operations. However, the number
of bit operations needed for integer division can be related to the number of
bit operations needed for integer multiplication. We state the following
theorem, which is basedon an algorithm which is discussedin Knuth 1561.

Theorem 1.7. There is an algorithm to find the quotient q:Ia/bl, when


the 2n-bit integer a is divided by the integer b having no more than n bits,
using O(M Q)) bit operations, where M fu) is the number of
bit operationsneededto multiply two n-bit integers.
42 The Integers

1.4 Problems

l. Add (l0llll0ll)2 and(ttootll0ll)2.

2 . S u b t r a c t( t o t t l 0 l 0 l ) 2 f r o m ( 1 1 0 1 1 0 1 1 0 0 ) 2 .

3. Multiply (t t rOr), and (l10001)2.

4. F i n d t h e q u o t i e n ta n d r e m a i n d e rw h e n ( t t o t o o n l ) 2 i s d i v i d e db y ( 1 1 0 1 ) 2 .

5. A d d ( A B A B ) 1 6a n d ( B A B A ) r c .

6. Subtract (CAFE)16 from (rnno)ru.

7. Multiply (FACE) 16and (BAD)rc.

8. Find the quotient and remainder when Gneono),u is divided by (enn.n)ru.


9. Explain how to add, subtract, and multiply the integers 18235187and 22135674
on a computer with word size 1000.

10. Write algorithms for the basic operations with integers in base (-2) notation
(see problem 6 of Section 1.3).

11. Give an algorithm for adding and an algorithm for subtracting Cantor
expansions (see problem l4 of Section 1.3).

12. Show that if f 1 and f 2 are O(St) and O(g2), respectively,and c1 and c2 are
constants,then c;f1 * ,zf z is O(g1 * g).

13. Show that if f is O(g), then fr it OQk) for all positiveintegersk.

14. Show that a function f is O(log2n) if and only if f is O(log,n) wheneverr ) l.


(Hint: Recall that logon/log6n: logo6.)

15. Show that the base b expansionof a positive integer n has llog6nl+t digits.

16. Analyzing the algorithms for subtraction and addition, show that with n-bit
integers these operationsrequire O h) bit operations.

17. Show that to multiply an n-bit and an m-bit integer in the conventional manner
requires OQm) bit operations.

18. Estimate the number of bit operationsneededto find l+2+ * n

il by performing all the additions.

b) by using the identity l+2* I n: nh+l)/2, and multiplying and


shifting.
1.4 Computer Operations with Integers 43

19. Give an estimate for the number of bit operationsneededto find

a) n'. b)
["1
|.o,|

20. Give an estimate of the number of bit operations needed to find the binary
expansionof an integer from its decimal expansion'

21. il Show there is an identity analogousto (1.6) for decimal expansions.

b) Using part (a), multiply 73 and 87 performing only three multiplications of


one-digit integers,plus shifts and additions.

c) Using part (a), reduce the multiplication of 4216 and 2733 to three
multiplications of two-digit integers, plus shifts and additions, and then
using part (a) again, reduce each of the multiplications of two-digit
integers into three multiplications of one-digit integers, plus shifts and
additions. Complete the multiplication using only nine multiplications of
one-digit integers, and shifts and additions.

22. il lf A and B are nxn matrices, with entries aii and bii for I ( i ( n,
I ( f ( n, then AB is the nxn matrix with entries cii : 2 ai*b*j.

Show that n3 multiplications of integers are used to find AB dir:;;ly from


its definition.

b) Show it is possible to multiply two 2x2 matrices using only seven


multiplications of integers by using the identity

o,rf lb,, D'tl


lo,,
l a z r o,,) lr,, t,,)
l"r r b r r* anbzt x I (a21
* a22)(bn-b,+
, )l

II
lx * (as-a2)(bzz-bn) -
a 2 2 ( br - b z r - b e * b 2 2 )
( a r r l a 1 2 - a 2 1 - a 2 2 )b 2 2

x * ( a n - a z t ) ( b r r - b r+r ) I
( a 2 1* a 2 ) ( b r z - b ' , - )
|

w h e r ex : a r r b r ,- ( a t t - c t 2 r - a 2 ) ( b n - bp* b2).

c) Using an inductive argument, and splitting 2nx2n matrices into four nxn
matrices, show that it is possibleto multiply two 2k x2k matrices using only
7ft multiplications, and less than 7ft+r additions.
44
The Integers

d) Conclude from part (c) that two nxn matrices can be multiplied using
O(nt"c7) bit operations when all entries of the matrices have less than c
bits, where c is a constant.
23. A dozen equals 12 and a gross equals 122. Using base 12, or duodecimal.
arithmetic answer the following questions.

il If 3 gross, 7 dozen, and 4 eggs are removed from a total of l l gross and 3
dozen eggs, how many eggs are left?

b) If 5 truckloads of 2 gross, 3 dozen, and 7 eggs each are delivered to the


supermarket, how many eggs were delivered?

c) If I I gross, I 0 dozen and 6 eggs are divided in 3 groups of equal size, how
many eggs are in each group?

24. A well-known rule used to find the square of an integer with decimal expansion
(an-1...apJro with final digit ao:5 is to find the decimal expansionof the
product (anan-1...a)rcl(anan-r...ar)ro* ll and append this with the digits
(25)ro. For instance, we see that the decimal expansion of (tOS)2 begins with
16'17 :272, so that (165)2 :27225. Show that the rule just describedis valid.

25. In this problem, we generalizethe rule given in problem 24 to find the squaresof
integers with final base 28 digit 8, where I is a positive integer. Show that the
base 28 expansion of the integer (ana,-1...afl0)z,astarts with the digits of the
base 28 expansionof the integer (anana...aflo)zn l(anan-1...ap0)zn* ll and
ends with the digits Bl2 and 0 when B is even, and the digits G-l)12 and.B
when I is odd.

1.4 Computer Projects

Write programs to do the following:

l. Perform addition with arbitrarily large integers.

2. Perform subtraction with arbitrarily large integers.

3. Multiply two arbitrarily large integers using the conventionalalgorithm.

4. Multiply two arbitrarily laige integers using the identity (1.6).

5. Divide arbitrarily large integers, finding the quotient and remainder.

6. Multiply two n xn matrices using the algorithm discussedin problem 22.


1.5 Prime Numbers 45

1.5 Prime Numbers


The positive integer I has just one positive divisor. Every other positive
integer has at least two positive divisors, becauseit is divisible by I and by
itself. Integers with exactly two positive divisors are of great importance in
number theory; they are called primes.

Definition. A prime is a positive integer greater than I that is divisible by no


positive integers other than I and itself.

Example. The integers2,3,5,13,101and 163 are primes.

Definition. A positive integer which is not prime, and which is not equal to l,
is called composite.

Example. The integers 4:2'2,8:4'2, 3 3 : 3 ' 1 1 ,1 l l : 3 ' 3 7 , a n d


l 0 0 l : 7' ll' 13 ar e co m p o s i te .

The primes are the building blocks of the integers. Later, we will show that
every positive integer can be written uniquely as the product of primes.
Here, we briefly discuss the distribution of primes and mention some
conjecturesabout primes. We start by showing that there are infinitely many
primes. The following lemma is needed.

Lemma 1.1. Every positive integer greater than one has a prime divisor.

Proof . We prove the lemma by contradiction; we assume that there is a


positive integer having no prime divisors. Then, since the set of positive
integers with no prime divisors is non-empty, the well-ordering property tells
us that there is a least positive integer n with no prime divisors. Since n has
no prime divisors and n divides n, we see that n is not prime. Hence, we can
write n:ab with I 1 a 1 n and | < b 1 n. Becausea 1 n. a must have
a prime divisor. By Proposition 1.3, any divisor of a is also a divisor of n, so
that n must have a prime divisor, contradicting the fact that n has no prime
divisors. We can conclude that every positive integer has at least one prime
divisor. tr
We now show that the number of primes is infinite.

Theorem 1.8. There are infinitely many primes.


46 The Integers

Proof . Consider the integer

Qn: nt t l, n 2 l.

Lemma 1.1. tells us that Q, has at least one prime divisor, which we denote
by gr. Thus, q, must be larger than n; for if 4, ( n, it would follow that
Qn I n!, and then, by Propositionl.!, Q, | (er-rr) : l, which is impossible.
Since we have found u priJ.''lur*r, tt* r, for every positive integer n,
there must be infinitely many primes. tr

Later on we will be interested in finding, and using, extremely large primes.


We will be concerned throughout this book with the problem of determining
whether a given integer is prime. We first deal with this question by showing
that by trial divisions of n by primes not exceeding the square root of n, we
can find out whether n is prime.

Thedrem 1.9. If n is a composite integer, then n has a prime factor not


exceeding..1n.

Proof . Since n is composite, we can write n : ab, where a and b are


integers with | 1a ( D < n. we must have a 4 r/i, since otherwise
b 7 a > ,/; and ab > '/i.,/i : n. Now, by Lemma I.l, a must have a
prime divisor, which by Proposition 1.3 is also a divisor of a and which is
clearly less than or equal to ,/i . D
We can use Theorem 1.9 to find all the primes less than or equal to a given
positive integer n. This procedure is called the steve of Eratosthenes. We
illustrate its use in Figure 1.2 by finding all primes less than 100. We first
note that every composite integer less than 100 must have a prime factor less
than J00-: 10. Since the only primes lessthan l0 are 2,3,4, and 7, we only
need to check each integer less than 100 for divisibility by these primes. We
first cross out, below by a horizontal slash -, all multiples of 2. Next we
cross out with a slash / those integers remaining that are multiples of 3.
Then all multiples of 5 that remain are crossedout, below by a backslash\.
Finally, all multiples of 7 that are left are crossedout, below with a vertical
slash l. ntt remaining integers (other than l) must be prime.
1.5 Prime Numbers 41

t23+ 5 +7+,/-1€-
ll ++ 13 l+- yr +#17+h19+
2{-*23+g-. X +/*2e-3o-
3l+2Ii+ 3? 37 +S- 2{ {'F
\
4r+43 1+ ,{ 1? 47 +F + {o-
+G -5S- 59 -6F
>{+*s3*r- \ .yr
61 4*tr# \ <G 67 +h t{ 1+
7t+73.+
't{=
r -7G
-8fi
I
T
-?& 7e -8€-
++
y{ t.> 83 \ "Yr +h 89
I
tlt +> 2< + 9t 9j -9t- .y +OF
\

Figure1.2. Findingthe PrimesLessThan 100Usingthe Sieveof Eratosthenes.


Although the sieveof Eratosthenesproducesall primes lessthan or equal to
a fixed integer, to determine whether a particular integer n is prime in this
manner, it is necessaryto check n for divisibility by all primes not exceeding
G. This is quite inefficient;later on we will have better methodsfor deciding
whetheror not an integeris prime.
We know that there are infinitely many primes, but can we estimate how
many primes there are less than a positivereal number x't One of the most
famous theorems of number theory, and of all mathematics, is the
prime number theorem which answersthis question. To state this theorem,
we introducesomenotation.

Definition. The function r(x), where x is a positivereal number, denotesthe


number of primes not exceedingx.

Example. From our exampleillustrating the sieveof Eratosthenes,


we seethat
o ( t O ) : 4 a n d z r ( t O O:)2 5 .
We now state the prime number theorem.

The Prime Number Theorem. The ratio of zr'(x) to x/log x approachesone as


x grows without bound. (Here log x denotesthe natural logarithm of x. In
th e languageof lim i ts ,w e h a v e l i m z r(x )/+ : l ).
. IOBX
48
The Integers

The prime number theorem was conjectured by Gauss in 1793, but


it was
not proved until 1896, when a French mathematician J. Hadamard
and a
Belgian mathematician C. J. de la Vall6e-Poussin produced independent
proofs. We will not prove the prime number theorem here; the varioui proofs
known are either quite complicated or rely on advanced mathematics. In
Table I .l we give some numerical evidence to indicate the validitv of the
theorem.

x rG) x /log x oG)/* ti G) r(x) /ti G)


log x

103 168 1 4 4 .8 1.160 1 7 8 0.9438202


104 t229 1085.7 1.132 -r 1246 0.9863563
105 9592 8 6 8 5 .9 l.104 9630 0.9960540
106 78498 72382.4 1.085 78628 0.9983466
107 664579 620420.7 1.071 664918 0.9998944
108 5761455 5428681.0 1.061 5762209 0.9998691
l0e 50847534 48254942.4 1.054 5084923s 0.9999665
l0l0 455052512 43429448r.9 1 .048 4 5 5 0 5 5 64 1 0.9999932
l 0 rI 4 r 1 8 0 5 4 8 1 3 3948131663.7 1 .043 4 1 1 8 1 6 5 4 0 1 0.999973r
l 0 l 2 3760791201836191206825.3 r.039 3760795028r 0.9999990
t 0 l 3 3460655 3 5 8 9t34072678387.r
8 1 . 0 3 6 34606564s8 10 0.9999997

Tablel.l. Approximations
to rG).
x'A"x
The prime number theorem tells us that x /log x is a good approximation to
rG) when x is large. It has been shown that an even better approximation is
given by

ld'i,
I' )':*4{
{-/d X/V614 -=1
L
ti G) :T O,
", log I

(whe-- T d, -^^-,
," J, representsthe areaunderthe curvey : lfiog t, and above
"* t :2 to / : x). In Table l.l, one seesevidencethat /i(x) is
the r-axis from
an excellent approximation of zr(x).

I'^
frtaft.1', nd -
r l'^- -L- =O\ J
v r ylr x4G ltlx
3
1.5 PrimeNumbers 49

We can now estimate the number of bit operations neededto show that an
',,6-. The
integer n is prime by trial divisionsof n by ail primes not exceeding
prime
',/n number theorem tells us that there are approximately
fioeJ; : 2-/i /log n primes not exceeding-6. To divide n by an integer
m takes O(log2n.log2m) Uit operations. Therefore, the number of bit
operations needed to show that n is prime by this method is at least
Q,/i/togilG log2n) - r,/i (where we have ignored thelog2m term since it
is at least l, even though it sometimesis as large as (log2n)/D . This method
of showing that an integer n is prime is very inefficient, for not only is it
necessaryto know all the primes not larger than ..li, but it is also necessaryto
do at least a constant multiple of ,/i bit operations. Later on we will have
more efficient methods of showing that an integer is prime.
We remark here that it is not necessaryto find all primes not exceedingx
in order to compute zr(x). One way that zr(x) can be evaluated without
finding all the primes less then x is to use a counting argument based on the
sieve of Eratosthenes (see problem l3). (Recently, very efficient ways of
finding r(x) using O (x3/s+c)bit operationshave been devisedby Lagarias and
Odlyzko t6ql.)
We have shown that there are infinitely many primes and we have discussed
the abundance of primes below a given bound x, but we have yet to discuss
how regularly primes are distributed throughout the positive integers. We first
give a result that shows that there are arbitrarily long runs of integers
containingno primes.

Proposition 1.8. For any positive integer n, there are at least n consecutive
compositepositive integers.

Proof. Consider the n consecutivepositive integers


h + l ) ! + 2 , ( n + 1 ) ! + 3 , . . . , h+ l ) ! + n t l .

When 2< j(n *l,weknowthatTl(n + l ) ! . B y P r o p o s i t i o1n. 4 , i t


follows that 7 | (, + t)! +;. Hence, these n consecutiveintegers are all
composite. tr

Example. The seven consecutiveintegers beginning with 8! + 2 : 40322 are


all composite. (However, these are much larger than the smallest seven
consecutivecomposites,90, 91, 92, 93, 94, 95, and 96.)
50 The Integers

Proposition1.8 showsthat the gap betweenconsecutiveprimes


is arbitrarily
long. On the other hand, primes may often be close iogether.
The only
consecutiveprimes are 2 and 3, because2 is the only even prime.
Howevei,
many pairs of primes differ by two; these pairs of pri-., are called
twin pr im es . E x a m p l e sa re th e p ri m e s 5 a n d 7,l l and 13, l 0l and
103, and
4967 and 4969. A famous unsettled conjecture assertsthat there are
infinitelv
many twin primes.

There are a multitude of conjecturesconcerningthe number of primes of


various forms. For instance,it is unknown whether there are infinitlly many
primes of the form n2 + | where n is a positiveinteger.
Questionssuch as this
may be easy to state, but are sometimesextremely difficult to resolve.
We conclude this section by discussing perhaps the most notorious
conjecture about primes.

Goldbach's Conjecture. Every even positive integer greater than two can be
written as the sum of two primes.
This conjecture was stated by Christian Goldbach in a letter to Euler in
1742. It has been verified for all even integersless than a million. One sees
by experimentation,as the following exampleillustrates,that usually there are
many sums of two primes equal to a particular integer, but a proof that there
always is at least one such sum has not yet been found.

Example. The integers 10,24, and 100 can be written as the sum of two
primes in the following ways:

l0:3+7:5t5,
24:5+lg:7+17:llf13,
100:3+97:ll*gg:17+93
:29*71:41+59:47+53.

1.5 Problems

l. Determinewhichof the followingintegersare primes

a) l0l c) l07 e) I 13
b) 103 d) lll f) tzt.
1.5 PrimeNumbers 51

2 . Use the sieveof Eratosthenesto find all primes lessthan 200'


3 . Find atl primes that are the difference of the fourth powers of two integers.
4 . Show that no integer of the form n3 * I is a prime, other than 2: 13 + l.

5 . Show that if a and n are positive integers such that an -l is prime, then a : 2
and n is prime. (Hint: Use the identity ake-l : Qk-D (aka-t\ +
a k Q - D+ + a k+ l ) .

6 . In this problem, another proof of the infinitude of primes is given. Assume there
are only finitely many primes p r,Pz,...,Pn Form the integer
... pn * l. Show that
Q: prpz Q h a s a p r i m e f a c t o r n o t i n t h e a b o v el i s t .
Conclude that there are infinitely many primes.

7. Let Qn : ptpz " ' pn t l where Pt,Pz, ..., Pn are the n smallest primes.
Determine the smallest prime factor of Q^ for n:1,2,3,4,5, and 6. Do you
think Q, is prime infinitely often? (tnis is an unresolvedquestion.)

8 . L e t p t , p 2 , . . . , p n b e t h e f i r s t n p r i m e sa n d l e t m b e a n i n t e g e rw i t h I 1 m
1n.
Let Q be the product of a set of z primes in the list and let R be the product of
the remaining primes. Show that Q + R is not divisible by any primes in the
list, and hence must have a prime factor not in the list. Conclude that there are
infinitely many primes.

9. Show that if the smallest prime factor p of the positive integer n exceedsd6
then n/p must be prime or 1.

1 0 . il Find the smallest five consecutivecomposite integers.


b) Find one million consecutivecompositeintegers.

I l. Show that there are no "prime triplets", i.e. primes p, p + 2, and p + 4, other
than 3,5, and 7.

12. Show that every integer greater than 11 is the sum of two compositeintegers.
( problem 17 of Section 1.1) to show that
13. Use the principle of inclusion-exclusion

-n
o(n):(o(.6-)-r) l-l . +l-ll
tl* l p ,I l p ,l )

l*l .l*l . +lrnl


wherept,pz,...,p,are the primeslessthan or equal to ^6 (with r:zr<Jill.
(Hint: Let propertyPi,,...,i,be the propertythat an integeris divisibleby all of
52 The Integers

Pi,,...,pi,,and use problem 23 of Section 1.2.)


14. Use problem l3 to find zr(250).

15' il show that the polynomial x2 -


x * 4l is prime for all integers x with
0 ( I < 40. Show, however,that it is composite
for x : 4i.
b) Show that if f (x) : onxn + an-,x;-t +
* a1x r as where the
coefficientsare integers, then there is an integer y
such that f(y) is composite.
(Hint: Assume that
f(x) :p is prim., unJsho* p divides (x+kfl
f for ail
integers ft ' conclude from the faci that a polynomial
of degree z takes on each
value at most n times, that there is an integer y
suctr that f(y) is composite.)
16' The lucky numbers are generated by the following
sieving process. Start with
the positive integers. Begin the process by crossing
out every second integer in
the list' starting your count with the integer t. other
than I the smallestinteger
left is 3, so we continue by crossing out every third integer
left, starting the
count with the integer l. The next integer left is 7, so we cross
out every seventh
integer left. Continue this process,where at each stage we
cross out every kth
integer left where & is the smallest integer left other than
one. The integers that
remain are the lucky numbers.

a) Find all lucky numbers less than 100.

b) show that there are infinitery many rucky numbers.

17. Show that if p is prime and I ( t ( p, then the binomial coefficient ,,


divisibleby p. [;]

1.5 Computer Projects

Write programs to do the following:

l' Decide whether an integer is prime using trial division of the


integer by all
primes not exceedingits square root.

2. Use the sieve of Eratosthenesto find all primes less than 10000.

3' Find zr(n), the number of primes lessthan or equal to rz, using problem
13.
4. verify Goldbach's conjecture for all even integers less than 10000.

5. Find all twin primes less than 10000.

6. Find the first 100 primes of the form n 2 + l.


7. Find the lucky numbers less than 10000 (see problem 16).
GreatestCommonDivisors
and Prime Factorization

2.1 GreatestCommonDivisors
If a and b are integers, that are not both zero, then the set of common
divisorsof a and 6 is a finite set of integers,alwayscontainingthe integers*l
and -1. We are interestedin the largest integer among the common divisors
of the two integers.

Definition. The greotest common divisor of two integers a and b, that are
not both zero, is the largest integer which divides both a and b.

The greatestcommondivisor of a and b is written as (a, b).

Example. The commondivisorsof 24 and 84 are t l, J.2, +3, 1.4, t6, and
+ 12. Hence Q+, g+) : 72. Similarly, looking at setsof commondivisors,we
f i n dt h a t ( 1 5 , 8 1 ): 3 , ( 1 0 0 , 5 ) : 5 , ( I 7 , 2 5 ) : l , ( 0 , 4 4 ): 4 4 , ( - 6 , - 1 5 ) : 3 ,
and (-17, 289) : 17.
We are particularly interested in pairs of integers sharing no common
divisorsgreaterthan l. Such pairs of integersare called relatively prime.

Definition. The integers a and b are called relatively prime if a and b have
greatestcommondivisor (a, b) : l.

Example. Since Q5,42) : 1,25 and 42 are relativelyprime.


53
54 GreatestCommonDivisorsand prime Factorization

Note that since the divisors of -c are the same as the divisors of a, it
follows that (a, b) : (lal, la ll (where lc I denotesthe absolute value of a
which equalsa if a )0 and equals -a if a <0). Hence, we can restrict our
attentionto greatestcommondivisorsof pairs of positiveintegers.
We now provesomepropertiesof greatestcommondivisors.

Proposition 2.1. Let a, b, and c be integerswith G, b) : d. Then


(;) b /d , b l d ) : I
(ii) (atcb, b) : (a, b).

Proof. (D Let a and b be integers with (a,b) : d. we will show that a /d


and b/d have no common positivedivisorsother than 1. Assume that e is a
positiveinteger such that e I Q/d) and e I Qtal. Then, there are integersk
and I with ald : ke and b/d :Qe, such that a : dek and b : de[. Hence.
de is a common divisor of a and b. Since d is the greatestcommon divisor of
o and b,e must be l . Consequently,G /d , b /d) : l.

(ii) Let a, b, and c be integers. We will show that the commondivisorsof a


and b are exactly the same as the common divisors of a t cb and b. This
will show that (a *cb , b) : G, b). Let e be a common divisor of a and b .
By Proposition1.4, we see that e I b*cb), so that e is a common divisor of
a * cb and 6. It,f is a commondivisor of a * cb and b, then by Proposition
1.4,we seethat/ dividesb+cb) - cb : a, so thatf is a commondivisorof
a and b. Hence G*cb, b) : (a, b'). a
We will show that the greatestcommon divisor of the integersa and b, that
are not both zero,can be written as a sum of multiplesof a and b. To phrase
this more succinctly,we use the following definition.

Definition. If a and b are integers,then a linear combination of a and b is a


sum of the form ma * nD, where both rn and,n are integers.
We can now state and prove the following theorem about greatest common
divisors.

Theorem 2.1. The greatest common divisor of the integers a and b, that are
not both zero, is the least positive integer that is a linear combination of a and
b.

Proof. Let d be the least positive integer which is a linear combination of a


and b. (There is a least such positive integer, using the well-ordering
property, since at least one of two linear combinations l'a t 0'b and
2,1 GreatestCommonDivisors 55

GDa + 0'b, wherea 10, is positive.)We write


rz.rlR==r* d:ma*nb,
?
w h e r em a n d n a r e p b f t @ i n t e g e r s .W e w i l l s h o w t h a t d l a a n d d l b .
By the divisionalgorithm,we have
a:dq*r, 0(r<d.

From'n"'o:'1'::^r:
:' ;: ;';::,b) : e-qm)a - qnb

This shows that the integer r is a linear combination of a and D. Since


0 ( r 1d, and d is the least positive linear combination of a and b, we
concludethat r : 0, and henced I o. In a similar manner,we can show that
d I b.
We now demonstratethat d is the greatest commondivisor of a and b. To
show this, all we need to show is that any common divisor c of a and D must
d i v i d e d . S i n c ed : m a * n b , i f c l a a n d c l b , P r o p o s i t i o nl . 4 t e l l s u s t h a t
c I d. tr
We have shown that the greatestcommon divisor of the integersa and b,
that are not both zero. is a linear combinationof a and b. How to find a
particular linear combinationof a and D equal to G, D) will be discussedin
the next section.
We can also definethe greatestcommondivisor of more than two integers.

Definition. Let e1, e2,...,en be integers, that are not all zero. The
greatest common divisor of these integers is the largest integer which is a
divisor of all of the integers in the set. The greatest common divisor of
a t, a 2 , . . .c, , is denot e db y (a 1 ,a 2 ,,...,
a n ).

Example. We easilyseethat 02, 18, 30) :6 and (10, 15, 25) : 5.


To find the greatestcommon divisor of a set of more than two integers,we
can use the following lemma.

L,emma2.1. If a1, a2,...,an are integers, that are not all zero, then
(a1, a2,..., an-1, an) : (a1, a2r..., (on-r, a)).

Proof. Any common divisor of the n integers ar, e2,...,en_t, en is, in


particular, a divisor of ar-1 and an, and therefore, a divisor of (an_1,an).
56 GreatestCommonDivisorsand PrimeFactorization

Also, any commondivisor of the n-2 integers4 t, a2,...,on_2,and (an_1,an),


must be a commondivisor of all n integers,for if it divides (on-r, an), it must
divide both cr-1 and an Since the set of n integersand the set of the first
n-2 integers together with the greatest common divisor of the last two
integers have exactly the same divisors, their greatest common divisors are
equal. tr

Example. To find the greatest common divisor of the three integers


105,140,and 3 5 0 , w e u s e L e mma 2 .1 to see that (105, 140.350) :
( 1 0 5 ,( 1 4 0 , 3 5 0 ):) ( l 0 5 , 7 0 ) : 3 5 .

Definition. We say that the integers a1.e2,...,e1 are mutually relatively


prime if (a1, e2,...,an) : l. These integers 4re called pairwise relatively
prime if for each pair of integers4; and a; from the set, (ai, a1): l, that is,
if each pair of integersfrom the set is relatively prime.
It is easy to see that if integersare pairwise relatively prime, they must be
mutually relatively prime. However, the converseis false as the following
exampleshows.

Example. Considerthe integers15, 21, and 35. Since


( 1 5 , 2 r , 3 5 ) (: t s ,( 2 t , 3 5 ) ) :( r 5 , 7 ) : r ,

we see that the three integersare mutually relatively prime. However, they
are not pairwise relatively prime, b e c a u s(et S . z l ) : 3 , ( 1 5 , 3 5 ): 5 , a n d
(21,35):7.

2.1 Problems

l. Find the greatestcommon divisor of each of the following pairs of integers

il 15,35 d) 99, 100


b) 0,lll e ) 1l , l 2 l
c) -12.t8 f) 100,102

Show that if a and b are integerswith (a, b) : l, then (a*b, a-b) : I or 2.

Show that if a and b are integers, that are not both zero, and c is a nonzero
i n t e g e r t, h e n ( c a, c b ) : l c l b , b \ .

4 . What is (a2+b2,a*b), where a and b are relatively prime integers,that are not
both zero?
2.1 GreatestCommonDivisors 57

5 . Periodicalcicadasare insectswith very long larval periodsand brief adult lives.


For each speciesof periodical cicada with larval period of 17 years, there is a
similar specieswith a larval period of 13 years. If both the l7-year and l3-year
speciesemerged in a particular location in 1900, when will they next both
emerge in that location?

6 . a) Show that if a and b are both even integers, that are not both zero, then
(a, b) : 2fu/2,b/2).

b) Show that if a is an even integer and b is an odd integer, then


G , b \ : G 1 2 b, ) .
7 . S h o w t h a t i f a , b , a n d c a r e i n t e g e r ss u c ht h a t G , b ) : I and c I G*b), then
k,a):(c,D)-L
8 . il Show that if a,b, and c a r e i n t e g e r sw i t h b , b ) : (a, c) : l, then
(a, bc) : L

b) Use mathematicalinductionto showthat if at, a2,...,anare integers,and b is


another integer such that (ar b) : (az, b) : : (on, b) - l, then
( a p 2 ' ' o n ,b ) : l .

9 . S h o wt h a t i f a , b , a n d c a r e i n t e g e r sw i t h c I a b , t h e n c | ( a , c ) ( b , c ) .
1 0 . a) Show that if a and b are positiveintegerswith (a , b) : l, then (an, bn) : I
for all positiveintegersn.

b) Use part (a) to prove that if a and b are integerssuch that a' I bn where n
is a positiveinteger,then c I b.

ll. Show that if a, b and c are mutually relatively prime nonzero integers, then
G, bd : (a,b)(a,c),
T2, Find a set of three integersthat are mutually relatively prime, but not relatively
prime pairwise. Do not use examplesfrom the text.

1 3 . Find four integersthat are mutually relatively prime, such that any two of these
integersare not relativelyprime.
1 4 . Find the greatestcommondivisor of each of the following setsof integers

a) 8, lo, 12 d) 6,15,21
b) 5,25,75 e) -7,28, -35
c ) 99,9999, 0 f) 0,0, l00l .

1 5 . Find three mutually relatively prime integers from among the integers
6 6 , 1 0 5 ,4 2 , 7 0 , a n d 1 6 5 .

1 6 . Show that ar, a2,...,an are integers that are not all zero and c is a positive
integer,then (cat, caz,...,can)- c(a6 a2...,an).
58 Greatest Common Divisors and Prime Factorization

t7. Show that the greatestcommon divisor of the integersat, o2,...,an, that are not
all zero,is the least positiveinteger that is a linear combinationof a t, at,..., an.

r 8 . Show that if k is an integer, then the six integers 6k-l, 6k +l ,


6k+2, 6k +3, 6k+5, are pairwiserelativelyprime.

r 9 . Show that if k is a positiveinteger,then 3k *2 and 5k +3 are relatively prime.

20. Show that every positive integer greater than six is the sum of two relativelv
prime integersgreater than I .

2t. a) Show that if a and b are relatively prime positive integers, then
(a'-b^)l(a-b).a-b) : I or n.

then ((an-b'\/G-b), a-b) :


b) Showthat if o and b arepositiveintegers,
( n ( a ,b ) r - t , a - b ) .

2.1 ComputerProjects
l. Write a programto find the greatest
commondivisorof two integers.

2.2The Euclidean
Algorithm
We are going to develop a systematicmethod, or algorithm, to find the
greatestcommon divisor of two positive integers. This method is called the
Euclidean algorithm. Before we discuss the algorithm in general, we
demonstrateits use with an example. We find the greatestcommon divisor of
30 and 72. F i rs t, w e u s eth e d i v i s i o na l g o ri t hmto w ri teT2:30' 2 + 12, and
w e u s e P r o p o s i t i o 2n . 1 t o n o t e t h a t $ 0 , 7 D : ( 3 0 ,7 2 - 2 . 3 0 ) : ( 1 0 , t 2 ) .
Another way to see that (J,0,7D: (30, 12) is to notice that any common
divisor of 30 and 72 must also divide 12 because12 : 72 - 30'2. and
conversely,any common divisor of 12 and 30 must also divide 72, since
72: 30' 2+ 12 . N o te w e h a v e re p l a c e d7 2 b y the smal l ernumber 12 i n our
computationssince 02,30): (30, l2). Next, we use the divisionalgorithm
again to write 30 : 2'12 + 6. Using the samereasoningas before,we seethat
( 30, 12) : ( 12 ,6 ). Be c a u s e 1 2 : 6 ' 2 * 0, we now see that
02, O : (6, 0) : 6. Consequently,we can conclude that (72,30) : 6,
without finding all the commondivisorsof 30 and 72.
We now set up the generalformat of the Euclideanalgorithm for computing
the greatestcommondivisor of two positiveinteger.

The EuclideanAlgorithm. Let rs : a and r r : b be nonnegativeintegerswith


b I 0. If the division algorithm is successively applied to obtain
r i : r i + t Q i * ,I r i + 2 w i t h 0 1 r i + 2 1 r i + t f o r 7 : 0 , 1 , 2 , . . . , n - 2 a n d r , : 0 ,

ot=bt *f^ O<rr<b


2 .2 Th e E uc lideanA l g o ri th m 59

then (a , b) -- r,-1, the last nonzeroremainder.

From this theorem,we see that the greatestcommon divisor of c and b is


the last nonzero remainder in the sequenceof equations generated by
successively using the division algorithm, where at each step, the dividend and
divisor are replacedby smaller numbers,namely the divisor and remainder.

To prove that the Euclidean algorithm producesgreatestcommon divisors,


the following lemma will be helpful.

Lemma 2.2. If c and d are integers and c : dq * r where c and d ate


i n te g er st,hen ( c , d) : (d , r).

Proof. If an integer e dividesboth c and d, then sincer : c-dq, Proposition


1 . 4 s h o w st h a t e l r . I f e l d a n d e l r , t h e n s i n c ec : d q l r , from
Proposition1.4, we seethat e I c. Since the common divisorsof c and d are
the sameas the commondivisorsof d and r, we seethat k, d) : (d, r). tr
We now prove that the Euclideanalgorithm works.

Proof. Let r0: e and rr : b be positive integers with a 7 b. By


applying the divisionalgorithm, we find that
successively

fg : rtQt*rZ 0< r2
f y : r2Q2* rt 0< r3

tn-3 : fn-2Qn-Z * fn-t 0 ( rr-r


f n-2 : fn-lQn-t * fn 0 (r,
I n-l : lnQn

We can assumethat we eventuallyobtain a remainder of zero since the


se q u enc eof r em aind e rsa : ro l r1 > . 1 2 > . ) 0 cannot contain more
than c terms. Bv Lemma 2.2. we see that ( a , b ) : ( r s , r 1 ) : ( r l , r z ) :
(rr., r) (rn-r, fn-t) : (rr-r, rr) : (rr,0) : rn. H ence
( a , b ) : r-. the last nonzeroremainder. tr

We illustrate the useof the Euclideanalgorithm with the following example.

Example. To find (252, 198), we use the division algorithm successivelyto


obtain
60 Greatest Common Divisors and Prime Factorization

2 5 2 : l . 1 g g+ 5 4
198:3'54 +36
54:1'36 +18
36 : 2.18.

H e n c eQ S Z . 1 9 8 ) : 1 8 .
Later in this section, we give estimates for the maximum number of
divisions used by the Euclidean algorithm to find the greatest common divisor
of two positive integers. However, we first show that given any positive integer
n, there are integersa and b such that exactly n divisionsare required to find
G, b) using the Euclidean algorithm. First, we define a special sequenceof
integers.

Definition. The Fibonacci numbers ur, u2, u3,... are defined recursively by
t h e e q u a t i o nas t : u 2 : I a n d u n : u n - t * u n - 2 f o rn 2 3 .
Us ing t he de fi n i ti o n , w e s e e th a t u 3 : tt2 * yt: I t | : 2, u3l u2
: 2 * I : 3, and so forth. The Fibonacci sequencebegins with the integers
1 , 1 , 2 , 3 , 5 , 8 1 3 , 2 1 , 3 4 , 5 5 ,8 9 , I 4 4 , . . . . E a c h s u c c e e d i nt g
erm is obtained
by adding the two previousterms. This sequenceis named after the thirteenth
century ltalian mathematicianLeonardodi Pisa, also known as Fibonacci,who
used this sequenceto model the population growth of rabbits (see problem 16
at the end of this section).
In our subsequentanalysis of the Euclidean algorithm, we wil! need the
following lower bound for the nth Fibonacci number.

Theorem 2.2. Let n be a positive integer and let cu: ( l+-.8) /2. Then
unlan-2forn73.

Proof. We use the second principle of mathematical induction to prove the


desired inequality. We have a 1 2: u3, so that the theorem is true for
n :3.
Now assumethat for all integersk with k 4 n, the inequality
ok-2 1 ut

holds.

S i n c ea : ( l + r f r / 2 i s a s o l u t i o no f x 2 - x - I : 0 , w e h a v ea 2 : a * l .
Hence,

otn-l : o2.on-3: (a*l).ar-3 : s1n-2 * an-3


2 .2 T he E uc lidean Al g o ri th m 61

By the induction hypothesis,we have the inequalities

an-2 < un, otn-31 un-t ,

Therefore, we conclude that


or'-l lun*un-l-un*l

This finishesthe proof of the theorem. tr


We now apply the Euclidean algorithm to the successiveFibonacci numbers
34 and 55 to find (34. 55). We have

55:34'l+21
34:21'l+13
2l: l3'l + 8
13:8'1 + 5
8 : 5'1 * 3
5:3'l * 2
3:2'l * I
2: l'2.

We observe that when the Euclidean algorithm is used to find the greatest
common divisor of the ninth and tenth Fibonacci numbers, 34 and 55, a total
of eight divisions are required. Furthermore, (34, 55) : 1. The following
theorem tells us how many divisions are needed to find the greatest common
divisor of successiveFibonacci numbers.

Theorem 2.3. Let unrr and unt2 be successive terms of the Fibonacci
sequence. Then the Euclidean algorithm takes exactly n divisions to show that
(u n * r , ur a2): l.

Proof. Applying the Euclidean algorithm, and using the defining relation for
the Fibonacci numbers ui : uj-r I ui-z in each step, we seethat

lln*2: Un*t'l t Un,


Un*l: Un'l + Un-1,

Lt4: u3'1* u2'


It3 : tt2'2.

Hence, the Euclidean algorithm takes exactly n divisions, to show that


( u n q 2 , t l n q r ): u z - l . E
62 Greatest Common Divisorsand Prime Factorization

We can now prove a theorem first proved by Gabriel Lame', a French


mathematician of the nineteenth century, which gives an estimate for the
number of divisions needed to find the greatest common divisor using the
Euclidean algorithm.

Lam6's Theorem. The number of divisions neededto find the greatest common
divisor of two positive integers using the Euclidean algorithm does not exceed
five times the number of digits in the smaller of the two integers.

Proof. When we apply the Euclidean algorithm to find the greatest common
divisor of a : re and b :r 1 with a ) b, we obtain the following sequenceof
equations:
fg : rtQt*rZ, 0(rz1rr,
f1 :rZ4Z*rt, 0(131rz,

fn-2 : fn-tQn-t * rr, 0 ( rn 1 rn-t,


fn-l : tnQn,

We have used n divisions. We note that each of the quotientsQt, Q2,...,Qn-l


is greater than or equal to l, and Qn 7 2, sincern 1rn-1. Therefore,
rr2l:ur,
rn-t 2 2rn 2 2u2: u3,
rn-z 2 rn-t * rn 2 ut * u2: u4,
rn-l 2 rn-z * rn-t 2 uq * u3: tt5,

rz)13*14 7 unq * un-z: u*


b:'r2rz * rt 7 u n * u n-t : un+ l

Thus, for there to be n divisions used in the Euclidean algorithm, we must


have b 7 un+r. By Theorem 2.2, we know that unay ) qn-r for n ) 2 where
a: (l+.,8)/2. Hence, b ) an-r. Now, since loglsa > 1/5, we seethat
l o g rq b > h -l )l o g l s a > (C I-l ) /5.

Consequently,
n-l(S'logleb.
2 .2 T he E uc lidean Al g o ri th m 63

Let b have k decimal {igits, so that b < 10ftand loglsb < k. Hence, we see
that n - I < 5k and since /c is an integer, we can conclude that n < 5k.
This establishesLam6's theorem. tr
The following result is a consequence
of Lam6's theorem.

Corollary 2.1. The number of bit operations needed to find the greatest
of twopositive
divisor
common integers
a and, yy
ir;;i.:f$;:ri?',
Proof. We know from Lam6's theorem that O Qogra) divisions, each taking
O(log2a)2) bit operations,are neededto find fu, b). Hence, by Proposition
1.7, (a, b) may be found using a total of O((log2a)3) bit operations. D
The Euclideanalgorithm can be used to expressthe greatestcommon divisor
of two integers as a linear combination of these integers. We illustrate this by
expressing(252, 198) : l8 as a linear combinationof 252and 198. Referring
to the stepsof the Euclideanalgorithm used to find (252, 198), from the next
to the last step, we seethat
18:54-l'36.

From the secondto the last step, it follows that


36:198-3'54,

which implies that


1 8: 5 4 - t . ( 1 9 8 - 3 . 5 4: ) 4 . 5 4 - 1 . 1 9 8 .

Likewise, from the first stepwe have


54:252 - l'198.

so that
l 8 - 4 ( 2 5 2 - 1 . 1 9 8- ) 1 . 1 9 8: 4 . 2 5 2 - 5 . 1 9 8 .

This last equationexhibits l8 : (252, 198) as a linear combinationof 252 and


l 98.
In general,to see how d : (a, b) may be expressedas a linear combination
of a and 6, refer to the series of equations that is generated by use of the
Euclideanalgorithm. From the penultimateequation,we have
rn: (a, b) : r n - 2 - r n - r Q n - .r

Th i s e x pr es s es
b, b) ' a s a l i n e a r c o mb i n a ti o no f rr-2e,fi drr-1. The secondto
64 GreatestCommonDivisorsand PrimeFactorization

the last equation can be used to expressr2-1 &S rn-3 -rn-zen-z . Using this
last equation to eliminate rn-1 in the previousexpressionfor (4,6), we find
that
ln: ln-3- fn-24n-2,

so that

b, b) : rn-2- (rn4-rn-zQn-z)en-r
-- (l + q rn Q n -z )rn - z-
Qn-rrn-3,

which expressesb, b) as a linear combinationof rn-2 zfid r,4. We continue


working backwards through the steps of the Euclidean algorithm to express
G, b) as a linear combinationof each precedingpair of remaindersuntil we
havefound (a, b) as a linear combinationof to: a and 11- b. Specifically,
if we have found at a particular stagethat

G,b):sriltrit,

then, since
ti: ti_2- ri_tQi_r,

we have

b,b) : s (ri-z*ri-g1-r) * tr1-r


: Q-sqt-)ri-r * sri-2.

This showshow to move up through the equationsthat are generatedby the


Euclidean algorithm so that, at each step, the greatestcommon divisor of a
and b may be expressedas a linear combination of a and b.

This method for expressingG, b) as a linear combinationof a and b is


somewhatinconvenientfor calculation, becauseit is necessaryto work out the
steps of the Euclidean algorithm, save all these steps, and then proceed
backwardsthrough the steps to write G,b) as a linear combinationof each
successivepair of remainders. There is another method for finding b,b)
which requires working through the steps of the Euclidean algorithm only
once. The following theoremgivesthis method.

Theorem 2.4. Let a and b be positive integers. Then

fu,b):sna+tnb,

for n:0,1,2,..., where,sn andtn are the nth terms of the sequences
defined
recursivelyby
2.2 The Euclidean Algorithm 65

SO: l, /0:0,
sl :0, /l : l,

and
si : Si*z- ?i-tsi-t, tj : tj-z - Q1-zt1-t

for 7 :2,3, ..., fl, where the q;'s are the quotientsin the divisionsof the
Euclideanalgorithm when it is usedto find G,b).

Proof. We will prove that

Q.D ri : sia + tjb

for 7 : 0, I ,...,fl. Since G,b) : r, once we have established(2.2), we will


know that
G,b):sna+tnb.

We prove (2.2) using the secondprinciple of mathematicalinduction. For


l :0 , we hav e a : r0 : l ' a * 0 ' b : s s a* ts b . H ence, Q.D i s val i d for
j : 0 . L i k e w i s eb, : r r : 0 ' a + l ' b : s l c + t f t , s o t h a t Q . D i s v a l i d f o r
j : l.

Now, assumethat
ri:Sia+tjb

for 7 : 1,2,..., k-1. Then, from the kth step of the Euclideanalgorithm,we
have
tk : rk-2 - r*_lQt-l .

Using the inductionhypothesis,we find that


r1 : (s1-2a*tp-2b) - (s1raa*t1r-1b) Q*-r
: (s 1 -2 -s * -tq * -)a * Q p 2 -t* -rq* -)b
:Ska+tkb.

This finishesthe proof. tr


The following example illustrates the use of this algorithm for expressing
(a,b) as a linear combinationof a and b.

Example. Let a :252 and D : 198. Then


66 GreatestCommonDivisorsand prime Factorization

so: l, lo:0,
sl :0, Ir : 1,
J2:S0-sql:l- 0'l:1, tZ:tO-ttQt:0- 1 . 1: - 1 ,
J 3 : S t - S Z Q z : 0- l ' 3 : - 3 , t 3 : t t - 1 Z Q Z :1 - ( - l ) 3 : 4 ,
s 4 : s 2- s t Q t : I - ( - l ) ' t : 4 , t q : t z - t t Q z : - l - 4 . 1: - 5 .

S i n c e1 4 : 1 8 : ( 2 5 2 , 1 9 8 )a n d 1 4 : s 4 o+ t 4 b , w e h a v e

1 8 - ( 2 5 2 ,1 9 8 ): 4 . 2 5 2- 5 . 1 9 8.

It should be noted that the greatestcommon divisor of two integersmay be


expressedin an infinite number of different ways as a linear combination of
theseintegers. To seethis, let d : (a,b) and let d : so I tb be one way to
write d as a linear combination of a and b, guaranteed to exist by the
previousdiscussion.Then

d : (s - k(b/d))a + Q - kb/d))b

for all integersk.

Example. With a :252 and b : 198, lB: (252, 198) : (+ - t Ik)252 +


(-S - l4k)198 whcneverk is an integer.

2.2 Problems

l. Use the Euclidean algorithm to find the following greatest common divisors

il (45,75) c) (ooo,
r+r+)
b) 002,22D d) (2078S,44350).

2. For each pair of integers in problem l, expressthe greatest common divisor of


the integers as a linear combination of these integers.

3. For each of the following sets of integers, expresstheir greatest common divisor
as a linear combination of these integers

il 6, 10,l5

b) 7 0 , 9 8 ,1 0 5

c) 2 8 0 ,3 3 0 , 4 0 5 , 4 9 0 .

4. The greatest common divisor of two integers can be found using only
subtractions, parity checks, and shifts of binary expansions,without using any
divisions. The algorithm proceedsrecursively using the following reduction
2.2 The Euclidean Algorithm 67

I, if a:b

)2 k l L ,b/2 ) if a and 6 are even


G.b): if a is even and b is odd
l{o/z,t)
-D,b) if a and b are odd.
[(a

a) Find (2106,8318) usingthis algorithm.

b) Show that this algorithm always produces the greatest common divisor of a
pair of positiveintegers.

5. In problem 14 of Section 1.2, a modified division algorithm is given which says


that if a and 6 > 0 are integers,then there exist unique integersq,r, and e
such that a : bq * er, where e - tl,r ) 0, and -blz < er { bl2. We can
set up an algorithm, analogous to the Euclidean algorithm, based on this
modified division algorithm, called the least-remainder algorithm. It works as
follows. Let rs: a and rr: b, where a ) b 7 0. Using the modified division
algorithm repeatedly,obtain the greatest common divisor of a and b as the last
nonzeroremainder rn in the sequenceof divisions

ro : rtQr * e2r2, -rtlz 1 e2r2 4 ,tlz

rn-Z : ln-tQn-t I enrn, -rn-tl2 I enrn 4, rn-tl2


fn-l : 7n4n'

a) Use the least-remainderalgorithm to find (384, 226).

b) Show that the least-remainder algorithm always produces the greatest


common divisorof two integers.

c) Show that the least-remainderalgorithm is always faster, or as fast, as the


Euclidean algorithm.

d) Find a sequenceof integers v6, V1,v2,... such that the least-remainder


algorithm takes exactly n divisionsto find (vn*,, vn+z).

e) Show that the number of divisions needed to find the greatest common
divisor of two positive integers using the least-remainderalgorithm is less
than 8/3 times the number of digits in the smaller of the two numbers,plus
413.
6 . Let m and n be positive integers and let a be an integer greater than one. Show
that (a^-1, an-l) - a(^' n)- l.

7 . In this problem, we discuss the game of Euclid. Two players begin with a pair
of positive integers and take turns making movesof the following type. A player
can move from the pair of positiveintegers{x,y} with x 2 y, to any of the pairs
[x-ty,yl, where / is a positive integer and x-ty 2 0. A winning move
68 GreatestCommonDivisorsand PrimeFactorization

consistsof moving to a pair with one element equal to 0.

a) Show that every sequence of moves starting with the pair {a, bl must
eventuallyend with the pair {0, (a, b)}.

b) show that in a game beginning with the pair {a, b},1he first player may
play a winning strategy if a - 6 or if a 7 b0+ Jil/z; otherwisethe
second player mgr play a winning strategy. (Hint: First show that if
y < x ( y(t+VS)/Z then thge is a unique move from l*,Ol that goes to
a pair lt, r| with y > ze+Jil/z.)

In problems8 to 16, un refers to the nth Fibonaccinumber.

8. Show that if n is a positiveinteger,then rz1l u2 I I ttr: un+z- l.


9. Show that if n is a positiveinteger, then unapn-r - u] : GD'.
10. Show that if n is a pqsitive integer, then un: (c'n-0\/'..fs, where
o : (t+.,6) /2 andp : Q-'./-il/2.

ll. Show that if m and n arepositiveintegerssuch that m I n, then u^ | un.

12. Show that if m and n are positiveintegers,then (u^, un) : u(m,il.

13. Show that un is even if and only if 3 | n.


(t 'l
t4. Letu: li i,.
Irn*, Itn I
a) Show that Un : .
lu, u^_r)

b) Prove the result of problem 9 by consideringthe determinant of Un.

15. We define the generalized Fibonacci numbers recursively by the equations


gr- a, E2: b, and gn - gn-t* gr-zfor n 2 3. Showthat gn: oun-2* bun-1
for n )- 3.

16. The Fibonacci numbers originated in the solution of the following problem.
Supposethat on January I a pair of baby rabbits was left on an island. These
rabbits take two months to mature, and on March I they produce another pair of
rabbits. They continually produce a new pair of rabbits the first of every
succeeding month. Each newborn pair takes two months to mature, and
producesa new pair on the first day of the third month of its life, and on the first
day of every succeedingmonth. Show that the number of pairs of rabbits alive
after n months is precisely the Fibonacci number un, assuming that no rabbits
ever die.
17. Show that every positive integer can be written as the sum of distinct Fibonacci
numbers.
2.3 The Fundamental Theorem of Arithmetic 69

2.2 Computer Projects

Write programs to do the following:

l. Find the greatestcommondivisor of two integersusing the Euclideanalgorithm.

2. Find the greatest common divisor of two integers using the modified Euclidean
algorithm given in problem 5.

3. Find the greatest common divisor of two integers using no divisions (see problem
0.
4. Find the greatest common divisor of a set of more than two integers.

5. Express the greatest common divisor of two integers as a linear combination of


theseintegers.

6. Express the greatest common divisor of a set of more than two integers as a
linear combination of these integers.

7. List the beginning terms of the Fibonacci sequence.

8. Play the game of Euclid describedin problem 7.

2.3 The FundamentalTheoremof Arithmetic


The fundamental theorem of arithmetic is an important result that shows
that the primes are the building blocks of the integers. Here is what the
theoremsays.

The Fundamental Theorem of Arithmetic. Every positive integer can be


written uniquely as a product of primes,with the prime factors in the product
written in order of nondecreasingsize.

Example. The factorizationsof somepositive integersare given by

2 4 0: 2 . 2 . 2 . 2 . 3:. 5 2 4 . 3 . 5 , 2 8: 9 1 7 . 1 7: 1 i 2 . 1 0 0 1: 7 . 1 1 . 1 3
.

Note that it is convenient to combine all the factors of a particular prime


into a power of this prime, such as in the previous example. There, for the
factorization of 240, all the fdctors of 2 were combined to form 24.
Factorizationsof integers in which the factors of primes are combined to form
powersare called prime-power factorizations.

To prove the fundamental theorem of arithmetic, we need the following


lemma concerningdivisibility.

Lemma 2.3. lf a, b, and c are positive integers such that (a, b) : I and
70 GreatestCommonDivisorsand PrimeFactorization

a I bc , t hen a I c ,

Proof. Since G,b): 1, there are integersx and y such that ax * by : y.


Multiplying both sides of this equation by c, we have acx * bcy: c. By
Proposition1.4, a divides acx * 6cy, since this is a linear combinationof a
and bc, both of which are divisibleby a. Hencea I c. a
The following corollary of this lemma is useful.

Corollary 2.2. If p dividasap2 an wherep is a prime and c r, a2,...,on


are positive integers, then there is an integer i with I < t ( n such that p
dividesa;.

Proof. We prove this result by induction. The case where n : I is trivial.


Assume that the result is true for n. Consider a product of n * t, integers,
ar az aral that is divisibleby the prime p. Sincep I ar az on*t:
(a1a2 an)ana1,we know from Lemma 2.3 that p I ar az en or
p I ar+r. Now, it p I ar az a' from the induction hypothesisthere is an
integer i with 1 < t ( n such Ihat p I ai. Consequentlyp I a; for some i
w i t h l < t < n * 1 . T h i s e s t a b l i s h e s t h e r e s ut rl t .
We begin the proof of the fundamental theorem of arithmetic. First, we
show that every positive integer can be written as the product of primes in at
least one way. We use proof by contradiction. Let us assume that some
positive integer cannot be written as the product of primes. Let n be the
smallest such integer (such an integer must exist from the well-ordering
property). lf n is prime, it is obviously the product of a set of primes, namely
t h e o n e p r i m e n .S o n m u s t b e c o m p o s i t Le e. t n : a b , w i t h | 1 a ( n a n d
| 1 b I n. But since a and b are smaller than n they must be the product
of primes. Then, since n : ab, we conclude that n is also a product of
primes. This contradictionshowsthat every positiveinteger can be written as
the product of primes.
We now finish the proof of the fundmental theorem of arithmetic by
showing that the factorization is unique.

Supposethat there is a positive interger that has more than one prime
factorization. Then, from the well-ordering property, we know there is a least
integer n that has at least two different factorizationsinto primes:
fl:PtPz Ps:QtQz Qt,

w h e r ep t , p 2 , . . . , p s , Q t , . . . , 4atr e a l l p r i m e s ,w i t h p r ( p z ( ( p, and
{r(42( (q'.
2.3 The Fundamental Theorem of Arithmetic 71

We will s how t ha t p t: Qr,p 2 : Q 2 ,...,a n d c o nti nueto show that each of


the successive p's and q's are equal, and that the number of prime factors in
the two factorizations must agree, that is s : /. To show that pr: Qr,
assumethat pr * qy Then, either pr ) 4r or pr 1 Qr By interchanging
the variables,if necessary, we can assumethat pr ( qr. Hence,pr 1q; for
i : 1, 2, . . . , ts inc e41 i s th e s m a l l e sot f th e q ' s . H e nce,pr tr qi for al l i . B ut,
from Corollary 2.2, we see that pr I qflz et : tt. This is a
contradiction. Hence, we can conclude that pr : Qr and
n /p r: pz pt p s : QzQ t Qt. S i n c e n l p l i s an i ntegersmal l erthan
n, and since n is the smallest positive integer with more than one prime
factorization,nfpl con be written as a product of primes in exactly one way.
Hence, each pi is equal to the correspondingq;, and s : /. This proves the
uniquenessof the prime factorization of positive integers. tr
The prime factorization of an integer is often useful. As an example, let us
find all the divisorsof an integer from its prime factorization.

Example. The positivedivisorsof 120 : 233'5 are thosepositiveintegerswith


prime power factorizationscontaining only the primes 2,3, and 5, to powers
lessthan or equal to 3, 1, and l, respectively.Thesedivisorsare
I 3 5 3'5:15
2 2 ' 3: 6 2 ' 5: 1 0 2 ' 3 ' 5: 3 0
22: 4 22.3: 12 22.5: 20 223.5: 6o
23:8 z3-3: 24 23.5: 40 23.3.s : l2o .

Another way in which we can use prime factorizations is to find greatest


common divisors. For instance,supposewe wish to find the greatest common
divisor of 720 : 2432'5and 2100 : 223'52'7. To be a commondivisor of both
720 and 2100, a positiveinteger can contain only the primes 2, 3, and 5 in its
prime-power factorization, and the power to which one of these primes appears
cannot be larger than either of the powersof that prime in the factorizations
of 720 and 2100. Consequently,to be a common divisor of 720 and 2100, a
positive integer can contain only the primes 2,3, and 5 to powers no larger
than2, l, and l, respectively.Therefore,the greatestcommon divisor of 720
a n d 2100is 22. 3. 5: 6 0 .
To describe, in general, how prime factorizations can be used to find
greatestcommondivsors,let min(a, D) denotethe smaller or minimum, of the
two numbers d and 6. Now let the prime factorizationsof a and b be

o : pi,pi2 .. . p:., b : p'r,plz.. . p:,,

where each exponent is a nonnegativeinteger and where all primes occurring


72 GreatestCommonDivisorsand PrimeFactorization

in the prime factorizationsof c and of b are included in both products,


perhapswith zero exponents. We note that

fu,b): pl'"k"0,)plinb,'b, p:'n(oro,) ,

sincefor eachprimepi, a and b shareexactlymin(a;,6;) factorsof p;.


Prime factorizationscan also be used to find the smallestinteger that is a
multiple of two positive integers. The problem of finding this integer arises
when fractions are added.

Definition. The least common multiple of two positive integersa and D is the
smallestpositiveinteger that is divisibleby a and b.

The leastcommonmultiple of a and b is denotedby Io, bl.

Example. We have the following least common multiples: ll5,2l l: 105,


lZ q, X l : 72, l Z , Z 0 l : 2 A ,a n d [7 , l l l : 7 7.
Once the prime factorizations of a and b are known, it is easy to find
I a, bl. I f a : p i ,p i , p l r. a n d ,b : p i ,pur2 .. . pun,w herept,pz,...,pn
are the primes occurring in the prime-powerfactorizationsof a and b, then
for an integer to be divisible by both c and D, it is necessarythat in the
factorization of the integer, eachp; occurs with a power at least as large as ai
and bi. Hence, [a,b], the smallestpositiveinteger divisible by both a and b
is
*Grb,) *Gru')
la,bl: pl Omaxb,'b,) pf

where max(x, /) denotesthe larger, or maximum, of x andy.

Finding the prime factorization of large integers is time-consuming.


Therefore, we would prefer a method for finding the least common multiple of
two integers without using the prime factorizations of these integers. We will
show that we can find the least common multiple of two positiveintegersonce
we know the greatest common divisor of these integers. The latter can be
found via the Euclideanalgorithm. First, we prove the following lemma.

Iemma 2,4. If x and y are real numbers, then max(x,y) + min(x,y)


:x+y.

P r o o f .I f x ) y , then min(x,y):y and max(x,!):x, so that


m a x ( x , y ) +m i n ( x , y ) : x * y . If x <y, then min(xy):x and
max(x,y): y, andagainwe findthat max(x,y)+ min(x,y) - x + y. tr
2.3 The Fundamental Theorem of Arithmetic 73

To find Ia, b l, once b, b) is known, we use the following theorem.

Theorem 2.5. lf a and b ate positive integers,then la,bl: ab/G,b),,


where Ia, b I and G, b) are the least common multiple and greatestcommon
divisor of c and b, respectively.

Proof. Let a and b have prime-power factorizations a : p\'pi' pl' and


t : pl'p!2 " ' p:', where the expnents are nonnegativeintegers and all
primes occurring in either factorization occur in both, perhaps with zero
exponents.Now let M1: max(c;, b;) and ffii -min(a1,b1). Then, we have

l a , b l b , i l : p Y ' p Y ' p { ' p T ' p T' ' 2


' pf'
: O{,+^,r{'*^' bY'*^'
: pl'+b'Oo'+b' p:'*o'
: p\'p;' pi'p"' po^'
: ab.

si n ceM i + f f ij: m ax (a y ,b j ) + m i n (a r' ,b ): a 1 * b 1 by Lemma2.4. tr

of the fundamentaltheoremof arithmetic will be


The following consequence
neededlater.

Lemma 2.5. Let m and n be relatively prime positive integers. Then, if d is


a positivedivisor of mn, there is a unique pair of positivedivisorsd 1 of m and
d2of n such that d : diz. Conversely,if dl and d2 are positivedivisor of z
andn, respectively, then d : dfl2is a positivedivisors of mn.

Proof. Let the prime-power factorizations of m and n be m : pT'pT'


p : ' and n: q i ' q i 2 " ' q i ' . Si n c e (m,n ) - l , the set of pri mes
p tPz,. . . , P s and t he s e t o f p ri me s Q t,4 2 ,...,4 th a ve no common el ements.
Therefore,the prime-powerfactorizationof mn is

mn: pT'pT' p!'qi'qi' q:' .

Hence,if d is a positivedivisor of mn, then

d:pi'piz "' pi'q{'qI' q{'

w h e r e0 ( e i (mi for i:1,2,...,s and 0(f (n; for 7:1,2,...,t.


Now let
74 GreatestCommonDivisorsand prime Factorization

dt : p't'ptz'

and

dr: q{'qI' q{' .

d : dfi2and(dr,d) : l. Thisis thedecomposition


Clearly of d wedesire.
Conversely,let dy and d2be positivedivisorsof m and n, respectively.Then

dr: p'r'ptr' p:'


wher e0 ( ei ( m i fo r i : 1 ,2 ,...,s , a n d

dr: q{'q[' q{'

where0 < /j ( n; for j : 1,2,...,t. The integer

d : dfi2: p'r'pi, . -. pi,q{,q[, q{'


is clearly a divisor of

mn: p?'pT' p!'qi'qi, ql,,


sincethe power of such prime occurring in the prime-powerfactorizationof d
is less than or equal to the power of that prime in the prime-power
factorization of mn. tr

A famous result of number theory deals with primes in arithmetic


progressions.

Dirichlet's Theorem on Primes in Arithmetic Progressions. Let a and b be


relatively prime positive integers. Then the arithmetic progression
an * b, f l : 1,2 ,3 ,..., c o n ta i n si n fi n i te l ym a n y pri mes.
G. Lejeune Dirichlet, a German mathematician, proved this theorem in
1837. Since proofs of Dirichlet's Theorem are complicated and rely on
advanced techniques, we do not present a proof here. However, it is not
difficult to prove special cases of Dirichlet's theorem, as the following
propositionillustrates.

Proposition 2.2. There are infinitely many primes of the form 4n * 3, where
n rs a positiveinteger.
2.3 The Fundamental Theorem of Arithmetic 75

Beforewe provethis result, we first prove a useful lemma.

Lemma 2.6. lf a and b are integers both of the form 4n * l, then the
product ab is also of this form.

Proof. Since a and b are both of the form 4n * l, there exist integers r and
s such that a : 4r * 1 and D : 4s * 1. Hence,

ab: ( + r + t ) ( 4 s + 1 ): 1 6 r s* 4 r * 4 s * l : 4 ( 4 r s + r * s ) * l,

which is again of the form 4n * 1. tr


We now provethe desiredresult.

Proof. Let us assume that there are only a finite number of primes of the
f o r m 4 n f 3 , s a yP o : 3 , P t , P 2 ,. . . ,P r . L e t

Q:4prpz P,*3.

Then, there is at least one prime in the factorizationof Q of the form 4n * 3.


Otherwise,all of these primes would be of the form 4n * 1, and by Lemma
2.6, this would imply that O would also be of this form, which is a
contradiction. However, none of the primes po, Pr,...,,Pndivides 0. The
prime 3 does not divide Q, for if 3 I Q, then I I (0-ll : 4pt pz p,,
which is a contradiction. Likewise, none of the primes p; can divide Q,
becausepj I Q impliespi | (Q-4pr pz p) :3 which is absurd. Hence,
there are infinitely many primesof the form 4n * 3. tr

2.3 Problems
L Find the primefactorizations
of
a) 36 e) 222 D 5o4o
b) 3e D 2s6 j) sooo
c) 100 d sr5 k) 9s5s
d) 289 h) 989 D 9999.

2. Show that all the powers in the prime-power factorization of an integer n are
even if and only if n is a perfect square.

3. Which positive integers have exactly three positive divisors? Which have exactly
four positivedivisors?

4. Show that every positive integer can be written as the product of a square and a
square-freeinteger. A square-free integer is an integer that is not divisible by
76 Greatest Common Divisors and Prime Factorization

any perfect squares.

5. An integer n is called powerful if whenevera prime p divides n, p2 divrdesn.


Show that every powerful number can be written as the product of a perfect
squareand a perfect cube.

6. Show that if a and b are positiveintegersand a3 | b2, then a I b.

7. Let p be a prime and n a positiveinteger. If p' I n, but po*' It n, we say that


po exactly divides n, and we write po ll n.

a) Show that if po ll m andpb ll n, then po*b ll mn.

b) S h o wt h a t i f p o l l m , t h e np k o l l m k .

c) Show that if po ll m andpb ll n, then ominb'b)


il m+ n.
8. a) Let n be a positiveinteger. Show that the power of the prime p occurring in
the prime power factorization of n ! is

ln/pl + Inlpzl + ln/p3l +

b) Use part (a) to find the prime-power factorization of 20!.

9. How many zerosare there at the end of 1000! in decimal notation? How many
in baseeight notation?

10. Find all positive integersn such that n! ends with exactly 74 zeros in decimal
notation.

ll. Show that if n is a positiveintegerit is impossiblefor n! to end with exactly 153,


154, or 155 zeroswhen it is written in decimal notation.

12. This problem presentsan example of a system where unique factorization into
primes fails. Let H be the set of all positiveintegersof the form 4ft*1, where k
is a positiveinteger.

a) Show that the product of two elementsof 11 is also in fI.

b) An element h*l in 11 is called a"Hilbert prime" if the only way it can be


written as the product of two integersin ^FIis h: h'l : l'ft, Find the 20
smallestHilbert primes.

c) Show every element of H can be factored into Hilbert primes.

d) Show that factorization of elements of FI into Hilbert primes is not


necessarilyunique by finding two different factorizationsof 693 into Hilbert
primes.

13. Which positiveintegersn are divisibleby all integersnot exceeding,,/;t

14. Find the least common multiple of each of the following pairs of integers
2.3 The Fundamental Theorem of Arithmetic 77

a) 8,12 d) lll,3o3
b) 14,15 e) 2 5 6 ,5 0 4 0
c) 28, 35 f) 3 4 3 ,9 9 9 .

15. Find the greatestcommondivisorand leastcommonmultipleof the following


pairsof integers
a) 22335s11,27355372
b) 2 . 3 . 5 . 7 I. '11 3 , 1 7 . t 9 . 2 3 . 2 9

c) 2 3 5t7t ' 3 , 2 . 3 . 5 . 1 t. .1t 3

d) 4 7 t t 7 g t n l 0 lr m r , 4 rl r 8 3 r r r l 0 l1 0 0 0 .

1 6 . Show that every common multiple of the positiveintegersa and b is divisibleby


the leastcommon multiple of a and b.

t 7 . Which pairs of integers a and D have greatest common divisor 18 and least
commonmultiple 540?

1 8 . Show that if a and b are positive integers, then (a , il | la, bl. When does
fu, b) : la, bl?
1 9 . Show that if a and b are positive integers, then there are divisors c of a and d
o f b w i t hG , d ) : I a n dc d : l a , b l .

20. Show that if a, b, and c are integers,then [a, Ull c if and only if a I c and
b I c.

21. a) Show that if a and b are positiveintegersthen (a,b) : (a*b,la,bD.

b) Find the two positive integers with sum 798 and least common multiple
l 0780.

2 2 . Show that if a,b, and c are positiveintegers,then (la, bl, t) : lG, c), (b, c)l
and lfu, b) , cJ : ([4, cl, lb , cl) .

23. a) Show that if a,b, and c are positiveintegers,then


m a x ( a , b , c ): a * b * c - m i n ( a , b ) - m i n ( a , c ) - m i n ( D , c )
* min(a,b,c).

b) Use part (a) to show that

a,brcla 'br'c.) .
. [a,b,clla,b,cl :
G , b ) G , c ) ( b, c )
24. Generalizeproblem 23 to find a formula for (ay,a2,...,on)'1d1,a2,...,an1
where
a 1.a2,...,a
n are positiveintegers.

25. The least common multiple of the integers a1,a2,...,an, that are not all zero, is
the smallestpositiveinteger that is divisible by all the integerso1,ct2,...,a,;
it is
78 GreatestCommonDivisorsand PrimeFactorization

denotedby Ia 5a2,...,an1.
il F i n d[ 6 , 1 0 , 1 5
a ]n d[ 7 , 1 1 , 1 3 j .
b) : l[,a1,a2,...,an-1l,anl.
Show that laya2,...,an-1,anl

26. Let n be a positive integer. How many pairs of positive integerssatisfy


Ia,bl: n?
27. Prove that there are infinitely many primes of the form 6ft * 5, where k is a
positive integer.

28. Show that if a and b are integers, then the arithmetic progression
a, a*b, a*Zb,... containsan arbitrary number of consecutivecompositeterms.

29. Find the prime factorizationsof

a) l06- l d) 224-l
b) lo8-l e) 230-l
c ) 2r 5- l f) 236-t.

30. A discount store sells a camera at a price less than its usual retail price of ,S99.
If they sell 88137 worth of this camera and the discounteddollar price is an
integer, how many camerasdid they sell?

31. il show that if p isa prime and,a is a positiveintegerwithp I a2, then p I a.

b) Show that if p is a prime, c is an integer, and n is a positive integer such


t h a t p l a n , t h e np l a .

32. Show that if a and b are positive integers, then a2 | b2 implies that a I b.
3 3 . Show that if a,b, and c are positive integers with (a ,b) : I and ab : cn, then
there are positive integers d and,e such that a : dn and b : en.

34. Show that if aya2,...,an are pairwise relatively prime integers, then
l a 1 , c t 2 , . . . ,: a a
npl 2''' sn.

2.3 Computer Projects

Write programs to do the following:

1. Find all positivedivisors of a positive integer from its prime factorization.

2. Find the greatest common divisor of two positive integers from their prime
factorizations.
3. Find the least common multiple of two positive integers from their prime
factorizations.

4. Find the number of zeros at the end of the decimal expansionof n ! where n is a
positiveinteger.
2.4 Factorization of Integers and the Fermat Numbers 79

5. Find the prime factorizationof n! where n is a positiveinteger.

2.4 Factorization of Integersand the Fermat Numbers


From the fundamental theorem of arithmetic, we know that every positive
integer can be written uniquely as the product of primes. In this section,we
discussthe problem of determiningthis factorization. The most direct way to
find the factorization of the positive integer n is as follows. Recall from
Theorem 1.9 that n either is prime, or else has a prime factor not exceeding
6 . Consequently,when we divide n by the primes 2,3,5,...not exceeding
,/i,*" either find a prime factorpr of n or elsewe concludethat r is prime.
If we have located a prime factor p r of n, we next look for a prime factor of
nt: nlp1, beginningour searchwith the prime p1, since n I has no prime
factor lessthan p1, nnd any factor of n1 is also a factor of n. We continue,if
necessary,determining whether any of the primes not exceeding rlr r divide
n1. We continue in this manner, proceedingrecursively,to find the prime
factorizationof n.

Example. Let n : 42833. We note that n is not divisible by 2,3 and 5, but
that 7 | n. We have
4 2 8 3 3- 7 . 6 1 1 9 .

Trial divisions show that 6119 is not divisible by any of the primes
7,11,13,17,I9,and 23. However,we seethat
6l19:29'2ll.

Since 29 > ,m, we know that 211 is prime. We conclude that the prime
factorizationof 42833is 42833 - 7 ' 29 ' 2ll.
Unfortunately,this method for finding the prime factorizationof an integer
is quite inefficient. To factor an integer N, it may be necessaryto perform as
many as r(JF) divisions, altogether requiring on the order of JF bit
operations,since from the prime number theorem zr(JF) is approximately
,N /tog..N : 2,N AogN, and from Theorem 1.7, thesedivisionstake at least
log N bit operations each. More efficient algorithms for factorization have
been developed, requiring fewer bit operations than the direct method of
factorization previously described. In general, these algorithms are
complicatedand rely on ideasthat we have not yet discussed.For information
about thesealgorithms we refer the reader to Guy [66] and Knuth [561. We
note that the quickest method yet devised can factor an integer N in
80 GreatestCommonDivisorsand PrimeFactorization

approximately

e*p(@)

bit operations,where exp standsfor the exponentialfunction.


In Table 2.1, we give the time required to factor integersof various sizes
using the most efficient algorithm known, where the time for each bit
operation has been estimated as one microsecond(one microsecondis 10-6
seconds).

Number of decimal digits Number of bit operations Time

50 l.4x10r0 3.9hours

75 9 . 0 xl 0 r 2 104days

100 2 . 3 xl 0 r 5 74 years

200 1.2x1023 3.8xl0e years

300 l.5xl02e years


4.9x1015

500 l.3xl03e years


4.2x102s
Table2.1. Time RequiredFor Factorization
of LargeIntegers.

Later on we will show that it is far easier to decide whether an integer is


prime, than it is to factor the integer. This difference is the basis of a
cyptographicsystemdiscussedin Chapter 7.
We now describea factorizationtechniquewhich is interesting,although it
is not always efficient. This technique is known as Fermat factorization and
is basedon the following lemma.

Lemma 2.7. lf n is an odd positive integer, then there is a one-to-one


correspondencebetween factorizations of n into two positive integers and
differencesof two squaresthat equal n.

Proof. Let n be an odd positive integer and let n : ab be a factorization of n


into two positive integers. Then n can be written as the differenceof two
squares,since

n:aD:
, l o + u l ' - ll-ol - u l '
| 2 ,l t 2 )'
l:l
2.4 Factorizationof Integersand the FermatNumbers 81

where G+b)12 and b-b)/2 are both integerssincea and b are both odd.

Conversely,if n is the differenceof two squares,say n: s2 - /2, then we


can factor n by noting that n : (s-l)(s+t). tr

To carry out the method of Fermat factorization,we look for solutionsof


the equation,, : *2 - yz by searchingfor perfect squaresof the form xz - n.
Hence, to find factorizationsof n, we search for a square among the sequence
of integers

t2-n, Q+Dz-n, (t+2)2-n,...

where I is the smallest integer greater than ,/i . This procedureis guaranteed
to terminate,sincethe trivial factorizationn : n'l leadsto the equation

n: fn+rl' lr-rl'
I r l- |. , ,l
Example. We factor 6077 using the method of Fermat factorization. Since
77 < ffi1 < 78, we look for a perfect square in the sequence

7 8 2- 6 0 7 7: 7
7 9 2- 6 0 7 7: 1 6 4
8 0 2- 6 0 7 7:3 2 3
812- 6077:484:222.

Since 6077:812 - 222. we conclude that 6077: $l-2D(8t+zz) :


59.103.
Unfortunately, Fermat factorization can be very inefficient. To factor n
using this technique, it may be necessary to check as many as
Q + D 12 - ,/n integers to determine whether they are perfect squares.
Fermat factorization works best when it is used to factor integers having two
factorsof similar size.
The integers Fn :22' + I are called the Fermat numbers. Fermat
conjectured that these integers are all primes. Indeed, the first few are
p r i m e s , n a m e l y F o : 3 , F 1 : 5 , F 2 : 1 7 ,F 3 : 2 5 7 , a n d F + : 6 5 5 3 7 .
Unfortunately,F5 :22'* 1 is compositeas we will now demonstrate.

Proposition 2,3. The Fermat number F5: 22'+ 1 is divisibleby 641.

Proof. We will prove that 641 | fr without actually performing the division.
Note that
82 GreatestCommonDivisorsand PrimeFactorization

6 4 1: 5 . 2 7 + l : 2 a + 54.
Hence.

22'+'
fil 'r'*'
-?;^i?ii:,:;o,2ii,Ii:,
=Z'ile
Therefore,we seethat 64t I F's. tr
The followingresult is a valuableaid in the factorizationof Fermat
numbers.

Proposition 2.4. Every prime divisor of the Fermat number F, :22' + | is


of the form2n+2k+ I.
The proof of Proposition2.4 is left until later. It is presentedas a problem
in Chapter 9. Here, we indicate how Proposition2.4 is useful in determining
the factorizationof Fermat numbers.

Example. From Proposition 2.4, we know that every prime divisor of


F 3: 22' + | :2 5 7 m u s t b e o f th e fo rm 2sk * l : 32.k + l . S i nce there
are no primes of this form less than or equal to ,/81, we can concludethat
Ft : 257 is prime.

Example. In attempting to factor F 6 : 22'+ l, we use Proposition2.4 to see


that all its prime factors are of the form 28k + l:256.k * l. Hence, we
need only perform trial divisionsof Foby those primes of the form 256'k + |
that do not exceed -,,/Fu. After considerablectmputation, one finds that a
pr im e div is o ri s o b ta i n e dw i th k : l 0 ? l ,i .e . Z74l i ' l : (256.10?l+ l ) I F6.

A great deal of effort has been devoted to the factorization of Fermat


numbers. As yet, no new Fermat primes have been found, and many people
believe that no additional Fermat primes exist. An interesting, but
impractical, primality test for Fermat numbers is given in Chapter 9.

It is possibleto prove that there are infinitely many primes using Fermat
numbers. We begin by showing that any two distinct Fermat numbers are
relativelyprime. The following lemma will be used.

Lemma 2.8. Let F1, :22' * I denote the kth Fermat number, where k is a
nonnegativeinteger. Then for all positiveintegersn , we have

FoFf z Fn-t: Fn - 2.
Proof. We will prove the lemma using mathematical induction. For n : 1,
the identity reads
2.4 Factorization of Integers and the Fermat Numbers 83

Fo : Fr - 2 '

This is obviouslytrue since F0 : 3 and Fr : 5. Now let us assumethat the


identity holds for the positiveinteger n, so that

FoFf z' ' ' Fn-r: F, - 2.

With this assumptionwe can easilyshow that the identity holds for the integer
n * I, since
FoFfz Fn-rFr: (FsFf2 "' Fr-)Fn
- ( F n - z ) F n : ( 2 2 '- D ( 2 2 ' + t )
- ( 2 2 ' 1 2- l - 2 2 ' * ' - 2 : F r a 1 -2. tr

This leadsto the following theorem.

Theorem 2.6. Let m and n be distinct nonnegative integers. Then the


Fermat numbersF^ and F, are relatively prime.

Proof. Let us assumethat m 1 n. From Lemma 2.8, we know that

Fffz''' F^' " F r - r: F n - 2 .

Assumethat d is a commondivisor of F* and Fo. Then, Proposition1.4 tells


u s th a t
d I G, - F s F .o
2 Fm F , -1) :2.

Hence, either d:l or d:2. However,since F, and Fn are odd, d cannot be


2. Consequently, d:l and (F^,F) : I. tr

Using Fermat numbers we can give another proof that there are infinitely
many primes. First, we note that from Lemma 1.1, every Fermat number Fn
has a prime divisor pr. Since (F*,F): l, we know that p^ # p, whenever
m # n. Hence,we can concludethat there are infinitely many primes.
The Fermat primes are also important in geometry. The proof of the
following famoustheoremmay be found in Ore [28].

Theorem 2.7. A regular polygon of n sidescan be constructedusing a ruler


a n d c om pas sif and o n l y i f n i s o f th e fo rm n :2 opl " ' pt w here p;,
i:1,2,...,t are distinct Fermat primes and a is a nonnegativeinteger.
84 GreatestCommonDivisorsand PrimeFactorization

2.4 Problems

l. Find the prime factorizationof the following positiveintegers

il egzgzt b) 1468789 c) SSOO8OZ9.

2. Using Fermat's factorization method, factor the following positive integers

a) 7709 d) I l02l
b) 73 e) 3200399
c) 10897 f) 24681023.

3. a) Show that the last two decimal digits of a perfect squaremust be one of the
followingpairs: 00, el, e4,25, o6, e9, where e standsfor any even digit and o
stands for any odd digit. (Hint: Show that n2, (50+n)2, and (50-n)2 all have
the same final decimal digits, and then consider those integers n with
0(n<2s.)
b) Explain how the result of part (a) can be used to speed up Fermat's
factorization method.

4. Show that if the smallestprime factor of n is p, then xz-n will not be a perfect
squarefor x ) h+pz) lLp .
5 . In this problem, we developthe method of Draim factorization. To search for a
factor of the positiveinteger n - nr, we start by using the division algorithm, to
obtain

i l 1: 3 q y * r y , 0(11 (3.

Settingntr - nr, we let

t/12: t/lt - Zqt, fl2: ttt2* 11.

We use the divisionalgorithm again, to obtain

f l 2 : 5 q 2 * 1 2 , 0 ( 1 2( 5 ,

and we let

3: rtl2 - 2qZ, fl1 : t 1 4 3* t2.

We proceedrecursively,using the division algorithm, to write

nx : (2k+l)qy * ry, 0 ( 11 < 2k+1,

and we define
2.4 Factorization of Integers and the Fermat Numbers 85

fllk : m*-t-2Qt-t, ttk : ttl* * rt-t.

We stop when we obtain a remaindet/1 : 0.

a) Show that n1 : knr - Qk+l) (qft q2*' ' ' + q,-) and rltk: n1-
2'(qftq2* *qo-r).

b) S h o wt h a t i f ( z * + t ) I , , t h e n ( 2 k + l ) I n r a n dn : ( 2 k * l ) m 1 , 1 1 .

c) Factor 5899 using the methodof Draim factorization.

6 . In this problem, we devel<lpa factorization technique known as Euler's method.


It'is applicablewhen the integer being factored is odd and can be written as the
sum of two squares in two different ways. Let n be odd and let
n:a2*b2:c2+d2, w h e r ea a n d c a r e o d d p o s i t i v ien t e g e r sa,n d b a n d d
are evenpositiveintegers.

a) Let u: (a-c,b-d). S h o w t h a t u i s e v e na n d t h a t i f r : ( a - c ) l u and


s : ( d - i l f u , t h e n ( r , s ) : l , r ( a * c ) : s ( d + b ) , a n ds I a + c .

b) L e t s v : a * c . S h o wt h a t r v : d + b , e : (a+cd+b), andv is even.

c) Concludethat n may be factoredas n:1fu12)2 + (v/2)zl(r2 + s2).

d) U s e E u l e r ' sm e t h o dt o f a c t o r 2 2 1 : 1 0 2 + l l 2 : 5 2 + 1 4 2 , 2 5 0 1: 5 0 2 + 1 2
: 492+ 102and 1000009: 10002+ 32 :9722 + 2352.

7 . Show that any number of the form 2an+2* I can be easily factored by the use of
the identity 4xa + 1 : (2x2+2x+l)(Zx2-Zx+t\. Factor 218+1 using this
identity.

8 . Show that if a is a positiveinteger and a^ *l is a prime, then m:2n for some


positive integer n. (Hint: Recall the identity a^*l: (aft + l)
(ak9-t)-akQ-D + -ae+l) wherem:kQ and { is odd).

9 . Show that the last digit in the decimal expansionof F, - 2r + | is 7 if n 7 2.


(Hint: Using mathematicalinduction, show that the last decimal digit of 22' is
6.)

10. Use the fact that every prime divisor of Fa:2t + I :65537 is of the form
26k + | - 64k * I to verify that F4 is prime. (You should need only one trial
division.)

I l. Use the fact that every prime divisor of Fz: 22'+ | is of the form
21k + | : l28k * 1 to demonstrate that the prime factorization of F5 is
F. : 641'6700417.

r2. Find all primesof the form 2T * 5, where n is a nonnegativeinteger.

1 3 . Estimate the number of decimal digits in the Fermat number Fn.


86 GreatestCommonDivisorsand PrimeFactorization

2.4 Computer Projects

Write programs to do the following:

l. Find the prime factorization of a positive integer.

2. Perform Fermat factorization.

3. Perform Draim factorization (see problem 5).

4. Check a Fermat number for prime factors, using Proposition 2.4.

2.5 LinearDiophantineEquations
Consider the following problem. A man wishes to purchase $510 of
travelers checks. The checks are available only in denominationsof $20 and
$50. How many of each denominationshould he buy? If we let x denotethe
number of $20 checks and y the number of $50 checks that he should buy,
then the equation 20x * 50y : 510 must be satisfied. To solvethis problem,
we need to find all solutions of this equation, where both x and y are
nonnegativeintegers.
A related problem arises when a woman wishes to mail a package. The
postal clerk determinesthe cost of postageto be 83 cents but only 6-cent and
15-centstampsare available. Can some combinationof thesestampsbe used
to mail the package? To answer this, we first let x denote the number of 6-
cent stampsand y the number of l5-cent stamps to be used. Then we must
have 6x + I5y : 83, where both x and y are nonnegativeintegers.
When we require that solutionsof a particular equationcome from the set
of integers,we have a diophantine equation. Diophantineequationsget their
name from the ancient Greek mathematician Diophantus, who wrote
extensivelyon such equations. The type of diophantine equation ax * by : c,
where a, b, and c are integersis called a linear diophanttne equations in two
variables. We now develop the theory for solving such equations. The
following theorem tells us when such an equation has solutions,and when
there are solutions,explicitly describesthem.

Theorem 2.8. Let a and D be positiveintegerswith d : (a,b). The equation


ax*by:c h a s n o i n t e g r a ls o l u t i o n si f d l c . lf dlc, then thereare
infinitely many integral solutions. Moveover, if x : x0, | - lo is a particular
solutionof the equation,then all solutionsare given by
x : xo+ (b/d)n, ! : yo- fuld)n,
Equations
2.5 LinearDiophantine 87

where n is an integer.

Proof. Assumethat x and y are integerssuch that ax I by : g. Then, since


dlo andd lb,byPropositio1 n . 4 ,d l t a s w e l l . H e n c e , ' rdf t r c , t h e r e a r e
no integral solutionsof the equation.
Now assumethat d | ,. From Theorem2.1, there are integerss and t with
(2.3) d:as+bt.

Sinced l r, there is an integere with de : c. Multiplying both sidesof (2.3)


bv e. we have
c:de:(as+bt)e:a(se) + bQe).

Hence, one solution of the equation is given by @Io,.wlere


-x0-'Ftf11*}f =7€. X * S€ rtacl I --te

To show that there are infinitely many solutions,let x:nfo+ $liln and
y:Y0 - G / d) n, wh e re n i s a n i n te g e r. W e s e e that thi s pai r (x,y) i s a
solution, since V rfi"v g rof14
ax t by : oxs* a(bld)n * byo- bGld)il: oxst bys: c.

We now show that every solutionof the equationax * by : c must be of the


form described in the theorern. Suppose that x and y are integers with
ax I bY : c. Since
a x s* b y o : , ,

by subtractionwe find that

G x * b y ) - ( a x s + b y s ): 0 ,

which impliesthat
a& - x/ + bU -.yd :0.

Hence,

a(x - xo): bjo- y).

Dividingboth sidesof this last equalityby d, we seethat

G l d ) (x - x s ) : (b l d ) U t - y).

By Proposition
2.1, we know that bld,bld): l. Using Lemma 2.3, it
88 GreatestCommonDivisorsand prime Factorization

follows that Q/d) | 9o- y). Hence, there is an integer n with


G/d)n:lo-l; t h i s m e a n st h a t y - l o - G / i l n . N o w p u t t i n gt h i s v a l u e
of y int o th e e q u a ti o n a (x - x d : bOo- y), w e fi nd that
aG - x d : b b /d )n , w h i c h i mp l i e sth a t x : x0 + (bl d)n. D

We now demonstratehow Theorem 2.8 is used to find the solutions of


particular linear diophantineequationsin two variables.

Consider the problems of finding all the integral solutions of the two
diophantine equationsdescribedat the beginning of this section. We first
considerthe equation6x + I5y : 83. The greatestcommon divisor of 6 and
15 is (6,15) : 3. Since I / gl, we know that there are no integral solutions.
Hence,no combinationof 6- and l5-cent stampsgivesthe correct postage.

Next, consider the equation 20x t 50y :519. The greatest common
divisor of 20 and 50 is (20,50): 10, and since l0 | 510, there are infinitely
many integral solutions. Using the Euclidean algorithm, wo find that
20eD * 50 : 10. Multiplying both sides by 51, we obtain
20(-102) + 50(51) : 510. Hence, a particular solution is given by
x 0: - 102 an d ./o :5 1 . T h e o re m2 .8 te l l s u s that al l i ntegralsol uti onsare
of the form x : -102 * 5n and y : 5l - 2n. Since we want both x and y
to be nonnegative,we must have - I02 + 5n ) 0 and 5l - 2n ) 0; thus,
n ) 20 2/5 and n 4 25 l/2. Since n is an integer, it follows that
n : 2 1 , 2 2 , 2 3 , 2 4 , o r 2 5 . H e n c e ,w e h a v et h e f o l l o w i n g5 s o l u t i o n sG: y ) :
( 3 , 9 ) ,( 8 , 7 ) ,( 1 3 , 5 ) ,( 1 9 , 3 ) ,a n d ( 2 3 , t ) .

2.5 Problems
l. For eachof the followinglineardiophantine
equations,
eitherfind all solutions,
or
showthat thereare no integralsolutions
a) 2x I 5y:11
b) l7x * l 3 y : 1 g g
c ) Z I x * l 4 y :1 4 7
d) 60x * l 8 y :9 7
e) t4o2x + t969y : r.
2. A studentreturningfrom Europechangeshis Frenchfrancs and Swissfrancs
into U.S. money. If he receives
$ll.9l and has receivedI7a for eachFrench
franc and 480 for eachSwissfranc, how much of eachtype of currencydid he
exchange?
2.5 Linear Diophantine Equations 89

3. A grocer orders apples and orangesat a total cost of $8.39. If apples cost him
25c each and oranges cost him 18c each and he ordered rnore apples than
oranges,how many of each type of fruit did he order? l€ I

4. A shopper spends a total of .85.49 for oranges, which cost l8o each, and
grapefruits, which cost 33c each. What is the minimum number of pieces of
fruit the shoppercould have bought?

5. A postal clerk has only l4-cent and 2l-cent stamps to sell. What combinations
of these may be used to mail a packagerequiring postageof exactly

a) .t3.50 b) $4.00 c) $ 7 .7 7 2

6. At a clambake, the total cost of a lobster dinner is $ I I and of a chicken dinner


is ,$8. What can you conclude if the total bill is

a) $777 b) $96 c) $692

7. Show that the linear diophantineequationafi1* a2x2* I anxn: b has


no solutionsif d / D, where d : (a1,a2,...,a11),
and has infinitely many solutionsif
d I b.
8. Find all integersolutionsof the followinglineardiophantine
equations
a) 2x*3yl4z:5
b) 7x*2ly*352:8
d l0lx * 10 2 y+ 1 0 3 2:1 .
of pennies,
9. Which combinations dimes,and quartershavea total value99c?
10. How manywayscanchangebe madefor onedollarusing
a) dimesand quarters
b) nickels.dimes,and quarters
c) pennies,
nickels,dimes,and quarters?
I l. Find all integersolutionsof the followingsystems
of lineardiophantineequations
a) x* y* z:100
x*8y*502:156
b) x+ y + z:100
x * 6y * 2lz :121
c) x* y* z + w-100
xt2y13z*4w-300
x*4y*9z1'16w-1000.
12. A piggy bank contains24 coins,all nickels,dimes,and quarters. If the total
of coinsare possible?
valueof the f,oinsis two dollars,what combinations
90 GreatestCommonDivisorsand PrimeFactorization

13. Nadir Airways offers three types of tickets on their Boston to New York flights.
First-classtickets are $70, second-class tickets are $55, and stand-by tickets are
$39. If 69 passengersp^y a total of $3274 for their tickets on a particular
flight, how many of each type of tickets were sold?

14. Is it possibleto have 50 coins,all pennies,dimes,and quartersworth,$3?

15. Let a and b be relatively prime positive integers and let n be a positive integer.
We call a solution x )) of the linear diophantine equation ax * by : n
nonnegativewhen both x and y are nonnegative.

il Show that whenevern 2 G-l)(6-l) there is a nonnegativesolution of


this equation.

b) Show that if n: ab - a - 6, then there are no nonnegativesolutions.

c) Show that there are exactly (a-1)$-D/2 positive integers n such that
the equation has a nonnegativesolution.

d) The post office in a small Maine town is left with stamps of only two
values. They discover that there are exactly 33 postage amounts that
cannot be made up using thesestamps,including 46c. What are the values
of the remainingstamps?

2.5 Computer Projects

Write programs to do the following:

1. Find the solutionsof a linear diophantine equation in two variables.

2. Find the positivesolutionsof a linear diophantine equation in two variables.

3. Find the solutionsof a linear diophantine equation in an arbitrary number of


variables.

4. Find all positive integers n for which the linear diophantine equation
ax * by : n has no positive solutions (see problem I 5).

You might also like