Rosen - Elementary Number Theory and Its Applications (001-100)
Rosen - Elementary Number Theory and Its Applications (001-100)
Rosen - Elementary Number Theory and Its Applications (001-100)
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
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
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.
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.
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
Bibliography
Appendix
List of Symbols
A list of the svmbols used in the text and where they are defined is
included.
Acknowledgments
Chapter3. 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
Chapter6. MultiplicativeFunctions
Chapter 7. Cryptology
Appendix.. 410
Answers to selected problems 426
Bibliography............. 438
List of symbols.... 445
Index 447
lntroduction
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.
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
are said to form a geometric progression. Also, a is called the initial term
and r is called the common ratio.
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
)
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
b oo:am*a^a1* *an.
k-m
and
I
k--2
2ori:e*ar*ar2+ *arn,
j-0
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:
We must show that the formula also holds for the positive integer n * l.
What we must show is that
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
bro:r*2+22+ *2',
k:0
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 .
n! : l'2'3 n
ft o, : ere2 an
j -r
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
(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
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.
|',]*, 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
I
ll
r2l
l33l
r4641
15101051
1615201561
172135352171
18285670562881
'Plr"urt
Figure1.1. triangle.
:
(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
(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 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
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
l0 l0
a) >2 c) 2j'
j-r j-r
l0 t0
u) 2i o) 22i.
j-l j-r
55
i l j -rl r 2 c) r. j'
)
b) trj 0) il2i
j-t j-l
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.
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.
, fr)
) (-r)o : o.
lrJ
[,lf,l|,,l
['J*l,J* I'J*
c) Findthesuml -2+22-23 + +2too.
| .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
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
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?
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!.
2. Evaluate n !
5. List the movesirr the Tower of Hanoi puzzle (see problem l8).
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.
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 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.
l b a n db l r , t h e n a l c .
1.3. If a,b,and c areintegerswitha
Proposition
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
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
a - b < btalbl 4 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).
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.
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 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
19. Show that if n is an integer and x is a real number, then [x*n] : [xl + n .
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
ln/2 if n is even
T(n) :
1Qn*D/z if n is odd.
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 .
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,
eo:bq1ta6 0(ar(6-t.
Q k - z: b q * - r * a k - r , 0 ( a 1 - 1 ( b - 1 ,
Qk-t: b.0 * ap, 0 ( a1 ( b-t.
n: beo* ao.
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.
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,
: bl(c1,-a1)bk-j-t + * (c7+r-or*,)
].
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.
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.
1.3 Problems
l. Convert (1999)1sfrom decimal to base 7 notation. Convert (6tOS)t from base 7
to decimal notation.
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,
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.
fl:ommt * a^a(m-l)! + * a 2 2 l* a 1 l !
1.3 Representationsof Integers 3t
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) 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 .
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.
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.
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).
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
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
ar * br t Co: C{ t rr,0 ( s1 ( r.
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
-(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.
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
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
oob:Qor*po,0(ps(r,
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
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
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
To find the other digits of q,, we define the sequenceof partial remainders
Ri by
Ro: a
and
Ri:Ri-r - bqn-trn-i
Rft:
Then
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
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 .
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).
so th at " f f z is 0( 96 ). tr
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
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).
considerably less than the exponent 2 that occurs in the estimate of the
number of bit operations needed for the conventional multiplication
algorithm.)
< , (3ttot'nl+t_rltoe'nl+t;
( 3 c .rl l o g Irn( 3 c .3 l o sr,:3rnto93
We now state, without proof, two pertinent theorems. Proofs may be found
in Knuth [50] or Kronsjii tSgl.
1.4 Problems
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 .
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 .
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).
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.
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'
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.
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?
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.
Definition. A positive integer which is not prime, and which is not equal to l,
is called composite.
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.
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
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
\
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.
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
a) l0l c) l07 e) I 13
b) 103 d) lll f) tzt.
1.5 PrimeNumbers 51
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.
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 )
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.
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.
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.
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.
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.
From'n"'o:'1'::^r:
:' ;: ;';::,b) : e-qm)a - qnb
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 ).
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)).
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
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
6 . a) Show that if a and b are both even integers, that are not both zero, then
(a, b) : 2fu/2,b/2).
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.
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.
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.
fg : rtQt*rZ 0< r2
f y : r2Q2* rt 0< r3
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.
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,
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
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,
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.
so that
l 8 - 4 ( 2 5 2 - 1 . 1 9 8- ) 1 . 1 9 8: 4 . 2 5 2 - 5 . 1 9 8 .
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,
G,b):sriltrit,
then, since
ti: ti_2- ri_tQi_r,
we have
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).
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 .
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.
d : (s - k(b/d))a + Q - kb/d))b
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).
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
b) Show that this algorithm always produces the greatest common divisor of a
pair of positiveintegers.
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
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.)
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. 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.
6. Express the greatest common divisor of a set of more than two integers as a
linear combination of these integers.
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
.
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 ,
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
Definition. The least common multiple of two positive integersa and D is the
smallestpositiveinteger that is divisibleby a and b.
dt : p't'ptz'
and
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
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,
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.
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
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 .
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.
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.
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 .
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 .
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.
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) .
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
28. Show that if a and b are integers, then the arithmetic progression
a, a*b, a*Zb,... containsan arbitrary number of consecutivecompositeterms.
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?
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. 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
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(@)
50 l.4x10r0 3.9hours
75 9 . 0 xl 0 r 2 104days
100 2 . 3 xl 0 r 5 74 years
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.
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.
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.
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 '
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
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].
2.4 Problems
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.
f l 2 : 5 q 2 * 1 2 , 0 ( 1 2( 5 ,
and we let
and we define
2.4 Factorization of Integers and the Fermat Numbers 85
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 .
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.
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.
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.
where n is an integer.
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.
G x * b y ) - ( a x s + b y s ): 0 ,
which impliesthat
a& - x/ + bU -.yd :0.
Hence,
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
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
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?
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.
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?
4. Find all positive integers n for which the linear diophantine equation
ax * by : n has no positive solutions (see problem I 5).