count additions used to increment the
loop variable.) 15. What is the largest n
for which one can solve within one second
a problem using an algorithm that
requires f (n) bit operations, where each
bit operation is carried out in 109
seconds, with these f

645 = 6561 mod 645 = 111; i = 9: Because
a9 = 1, we find that x = (471 111) mod
645 = 36. This shows that following the
steps of Algorithm 5 produces the result
3644 mod 645 = 36. Algorithm 5 is
quite efficient; it uses O(log m)2 log n)
bit operations to

are interested in ordered
arrangements of some of the elements
of a set. An ordered arrangement of r
elements of a set is called an rpermutation. P1: 1 CH06-R2 Rosen2311T MHIA017-Rosen-v5.cls May 13,
2011 10:25 408 6 / Counting EXAMPLE
2 Let S = cfw_1, 2,

each of these integers to a binary
expansion. a) (80E)16 b) (135AB)16 c)
(ABBA)16 d) (DEFACED)16 8. Convert
(BADFACED)16 from its hexadecimal
expansion to its binary expansion. 9.
Convert (ABCDEF)16 from its
hexadecimal expansion to its binary
expansion.

a11!, where ai is an integer with 0 ai i
for i = 1, 2,.,n. 48. Find the Cantor
expansions of a) 2. b) 7. c) 19. d) 87. e)
1000. f ) 1,000,000. 49. Describe an
algorithm that finds the Cantor expansion
of an integer. 50. Describe an algorithm
to add two in

impossible to have a computer linked
to none of the others and a computer
linked to all the others.] 38. Find the
least number of cables required to
connect eight computers to four
printers to guarantee that for every
choice of four of the eight computers

many ways are there to select 47 cards
from a standard deck of 52 cards?
Solution: Because the order in which
the five cards are dealt from a deck of
52 cards does not matter, there are
C(52, 5) = 52! 5!47! different hands of
five cards that can be dealt.

2008. A communal effort, the Great
Internet Mersenne Prime Search (GIMPS),
is devoted to the search for new Mersenne
primes. You can join this search, and if you
are lucky, find a new Mersenne prime and
possibly even win a cash prize. By the
way, even the

any order, there are 6! = 720
permutations of the letters ABCDEFGH
in which ABC occurs as a block.
Combinations We now turn our
attention to counting unordered
selections of objects. We begin by
solving a question posed in the
introduction to this sectio

have these values, we multiply the terms
b2j in this list, where aj = 1. (For
efficiency, after multiplying by each term,
we reduce the result modulo m.) This
gives us bn. For example, to compute 311
we first note that 11 = (1011)2, so that
311 = 383231.

total of O(n2) additions of bits are
required for all n additions.
Surprisingly, there are more efficient
algorithms than the conventional
algorithm for multiplying integers. One
such algorithm, which uses O(n1.585) bit
operations to multiply n-bit numbe

a0 at x = c can be expressed in
pseudocode by procedure polynomial(c,
a0, a1,.,an: real numbers) power := 1 y :=
a0 for i := 1 to n power := power c y := y
+ ai power return y cfw_y = ancn +
an1cn1 + a1c + a0 where the final
value of y is the value of the

Example 12. EXAMPLE 12 Use Algorithm
5 to find 3644 mod 645. Solution:
Algorithm 5 initially sets x = 1 and power
= 3 mod 645 = 3. In the computation of
3644 mod 645, this algorithm determines
32j mod 645 for j = 1, 2,., 9 by
successively squaring and red

d r := r d q := q + 1 if a < 0 and r > 0 then
r := d r q := (q + 1) return (q, r) cfw_q = a
div d is the quotient, r = a mod d is the
remainder There are more efficient
algorithms than Algorithm 4 for
determining the quotient q = a div d and
the remainder

permutations of a set with eight
elements. Hence, there are P (8, 3) = 8
7 6 = 336 possible ways to award the
medals. EXAMPLE 6 Suppose that a
saleswoman has to visit eight different
cities. She must begin her trip in a
specified city, but she can visit

of its decimal digits in odd-numbered
positions is divisible by 11. 33. Show that
a positive integer is divisible by 3 if and
only if the difference of the sum of its
binary digits in evennumbered positions
and the sum of its binary digits in oddnumbered

The algorithm should loop through the
subsets; for each subset Si, it should then
loop through all other subsets; and for
each of these other subsets Sj , it should
loop through all elements k in Si to
determine whether k also belongs to Sj .]
b) Give a b

there are infinitely many primes; the
proof of this fact, found in the works of
Euclid, is famous for its elegance and
beauty. We will discuss the distribution of
primes among the integers. We will
describe some of the results about primes
found by mathem

claimed is maintained by God. By the way,
there are a vast number of different
proofs than there are an infinitude of
primes, and new ones are published
surprisingly frequently. THEOREM 3
There are infinitely many primes. Proof:
We will prove this theorem

The P (n, r) r-permutations of the set
can be obtained by forming the C(n, r)
r-combinations of the set, and then
ordering the elements in each rcombination, which can be done in P (r,
r) ways. Consequently, by the product
rule, P (n, r) = C(n, r) P (r, r

four elements in a list of 32 elements.
Would a linear search or a binary search
locate this element more rapidly? 8. Given
a real number x and a positive integer k,
determine the number of multiplications
used to find x2k starting with x and
successively

Descartes and Galileo, from religious
critics. He also helped expose alchemists
and astrologers as frauds. P1: 1 CH04-7R
Rosen-2311T MHIA017-Rosen-v5.cls May
13, 2011 10:24 262 4 / Number Theory
and Cryptography of prime numbers to
gather evidence concern

that are divisible by 2, other than 2, are
deleted. Because 3 is the first integer
greater than 2 that is left, all those
integers divisible by 3, other than 3, are
deleted. Because 5 is the next integer left
after 3, those integers divisible by 5, other

colony west of Egypt, and spent time
studying at Platos Academy in Athens. We
also know that King Ptolemy II invited
Eratosthenes to Alexandria to tutor his
son and that later Eratosthenes became
chief librarian at the famous library at
Alexandria, a cent

algorithm (used when multiplying with
pencil and paper) works as follows. Using
the distributive law, we see that ab =
a(b020 + b121 + bn12n1) = a(b020)
+ a(b121) + a(bn12n1). We can
compute ab using this equation. We first
note that abj = a if bj = 1 and

that the binary expansion of a positive
integer can be obtained from its octal
expansion by translating each octal digit
into a block of three binary digits. 17.
Convert (7345321)8 to its binary
expansion and (10 1011 1011)2 to its
octal expansion. 18. Gi

elements does a set with 10 elements
have? 17. How many subsets with more
than two elements does a set with 100
elements have? 18. A coin is flipped
eight times where each flip comes up
either heads or tails. How many
possible outcomes a) are there in
tot

as an octal expansion. a) (763)8, (147)8
b) (6001)8, (272)8 c) (1111)8, (777)8 d)
(54321)8, (3456)8 24. Find the sum and
product of each of these pairs of numbers.
Express your answers as a hexadecimal
expansion. a) (1AE)16, (BBC)16 b)
(20CBA)16, (A01)16

is a function fromS to T , where S and T
are nonempty finite sets and m = |S| / |
T |, then there are at least m elements
of S mapped to the same value of T .
That is, show that there are distinct
elementss1, s2,.,sm of S such that f
(s1) = f (s2) = f (sm