17.9 KB · commit a9602da
The part of mathematics devoted to the study of the set of integers and their properties is known as number theory. In this chapter we will develop some of the important concepts of number theory including many of those used in computer science. As we develop number theory, we will use the proof methods developed in Chapter 1 to prove many theorems.
We will first introduce the notion of divisibility of integers, which we use to introduce modular, or clock, arithmetic. Modular arithmetic operates with the remainders of integers when they are divided by a fixed positive integer, called the modulus. We will prove many important results about modular arithmetic which we will use extensively in this chapter.
Integers can be represented with any positive integer b greater than 1 as a base. In this chapter we discuss base b representations of integers and give an algorithm for finding them. In particular, we will discuss binary, octal, and hexadecimal (base 2, 8, and 16) representations. We will describe algorithms for carrying out arithmetic using these representations and study their complexity. These algorithms were the first procedures called algorithms.
We will discuss prime numbers, the positive integers that have only 1 and themselves as positive divisors. We will prove that there are infinitely many primes; the proof we give is considered to be one of the most beautiful proofs in mathematics. We will discuss the distribution of primes and many famous open questions concerning primes. We will introduce the concept of greatest common divisors and study the Euclidean algorithm for computing them. This algorithm was first described thousands of years ago. We will introduce the fundamental theorem of arithmetic, a key result which tells us that every positive integer has a unique factorization into primes.
We will explain how to solve linear congruences, as well as systems of linear congruences, which we solve using the famous Chinese remainder theorem. We will introduce the notion of pseudoprimes, which are composite integers masquerading as primes, and show how this notion can help us rapidly generate prime numbers.
This chapter introduces several important applications of number theory. In particular, we will use number theory to generate pseudorandom numbers, to assign memory locations to computer files, and to find check digits used to detect errors in various kinds of identification numbers. We also introduce the subject of cryptography. Number theory plays an essential role both in classical cryptography, first used thousands of years ago, and modern cryptography, which plays an essential role in electronic communication. We will show how the ideas we develop can be used in cryptographical protocols, introducing protocols for sharing keys and for sending signed messages. Number theory, once considered the purest of subjects, has become an essential tool in providing computer and Internet security.
The ideas that we will develop in this section are based on the notion of divisibility. Division of an integer by a positive integer produces a quotient and a remainder. Working with these remainders leads to modular arithmetic, which plays an important role in mathematics and which is used throughout computer science. We will discuss some important applications of modular arithmetic later in this chapter, including generating pseudorandom numbers, assigning computer memory locations to files, constructing check digits, and encrypting messages.
When one integer is divided by a second nonzero integer, the quotient may or may not be an integer. For example, 12/3=4 is an integer, whereas 11/4=2.75 is not. This leads to Definition 1.
In Figure 1 a number line indicates which integers are divisible by the positive integer d.
Figure 1 — Integers Divisible by the Positive Integer d.
Determine whether 3∣7 and whether 3∣12.
Solution: We see that 3∤7, because 7/3 is not an integer. On the other hand, 3∣12 because 12/3=4. ◀
Let n and d be positive integers. How many positive integers not exceeding n are divisible by d?
Solution: The positive integers divisible by d are all the integers of the form dk, where k is a positive integer. Hence, the number of positive integers divisible by d that do not exceed n equals the number of integers k with 0<dk≤n, or with 0<k≤n/d. Therefore, there are ⌊n/d⌋ positive integers not exceeding n that are divisible by d. ◀
Some of the basic properties of divisibility of integers are given in Theorem 1.
Proof: We will give a direct proof of (i). Suppose that a∣b and a∣c. Then, from the definition of divisibility, it follows that there are integers s and t with b=as and c=at. Hence, b+c=as+at=a(s+t). Therefore, a divides b+c. This establishes part (i) of the theorem. The proofs of parts (ii) and (iii) are left as Exercises 3 and 4. ■
Theorem 1 has this useful consequence.
Proof: We will give a direct proof. By part (ii) of Theorem 1 we see that a∣mb and a∣nc whenever m and n are integers. By part (i) of Theorem 1 it follows that a∣mb+nc. ■
When an integer is divided by a positive integer, there is a quotient and a remainder, as the division algorithm shows.
We defer the proof of the division algorithm to Section 5.2.
Examples 3 and 4 illustrate the division algorithm.
What are the quotient and remainder when 101 is divided by 11?
Solution: We have 101=11⋅9+2. Hence, the quotient when 101 is divided by 11 is 9=101 div 11, and the remainder is 2=101mod11. ◀
What are the quotient and remainder when −11 is divided by 3?
Solution: We have −11=3(−4)+1. Hence, the quotient when −11 is divided by 3 is −4=−11 div 3, and the remainder is 1=−11mod3.
Note that the remainder cannot be negative. Consequently, the remainder is not −2, even though −11=3(−3)−2, because r=−2 does not satisfy 0≤r<3. ◀
Note that the integer a is divisible by the integer d if and only if the remainder is zero when a is divided by d.
In some situations we care only about the remainder of an integer when it is divided by some specified positive integer. For instance, when we ask what time it will be (on a 24-hour clock) 50 hours from now, we care only about the remainder when 50 plus the current hour is divided by 24. Because we are often interested only in remainders, we have special notations for them. We have already introduced the notation amodm to represent the remainder when an integer a is divided by the positive integer m. We now introduce a different, but related, notation that indicates that two integers have the same remainder when they are divided by the positive integer m.
Although both notations a≡b(modm) and amodm=b include "mod," they represent fundamentally different concepts. The first represents a relation on the set of integers, whereas the second represents a function. However, the relation a≡b(modm) and the modm function are closely related, as described in Theorem 3.
The proof of Theorem 3 is left as Exercises 15 and 16. Recall that amodm and bmodm are the remainders when a and b are divided by m, respectively. Consequently, Theorem 3 also says that a≡b(modm) if and only if a and b have the same remainder when divided by m.
Determine whether 17 is congruent to 5 modulo 6 and whether 24 and 14 are congruent modulo 6.
Solution: Because 6 divides 17−5=12, we see that 17≡5(mod6). However, because 24−14=10 is not divisible by 6, we see that 24≡14(mod6). ◀
The concept of congruences was developed by Karl Friedrich Gauss at the end of the eighteenth century. The notion of congruences has played an important role in the development of number theory.
Theorem 4 provides a useful way to work with congruences.
Proof: If a≡b(modm), by the definition of congruence (Definition 3), we know that m∣(a−b). This means that there is an integer k such that a−b=km, so that a=b+km.
Conversely, if there is an integer k such that a=b+km, then km=a−b. Hence, m divides a−b, so that a≡b(modm). ■
The set of all integers congruent to an integer a modulo m is called the congruence class of a modulo m. In Chapter 9 we will show that there are m pairwise disjoint equivalence classes modulo m and that the union of these equivalence classes is the set of integers.
Theorem 5 shows that additions and multiplications preserve congruences.
Proof: We use a direct proof. Because a≡b(modm) and c≡d(modm), by Theorem 4 there are integers s and t with b=a+sm and d=c+tm. Hence, b+d=(a+sm)+(c+tm)=(a+c)+m(s+t) and bd=(a+sm)(c+tm)=ac+m(at+cs+stm). Hence, a+c≡b+d(modm) and ac≡bd(modm). ■
Because 7≡2(mod5) and 11≡1(mod5), it follows from Theorem 5 that 18=7+11≡2+1=3(mod5) and that 77=7⋅11≡2⋅1=2(mod5). ◀
Corollary 2 shows how to find the values of the modm function at the sum and product of two integers using the values of this function at each of these integers. We will use this result in Section 5.4.
Proof: By the definitions of modm and of congruence modulo m, we know that a≡(amodm)(modm) and b≡(bmodm)(modm). Hence, Theorem 5 tells us that a+b≡(amodm)+(bmodm)(modm) and ab≡(amodm)(bmodm)(modm). The equalities in this corollary follow from these last two congruences by Theorem 3. ■
We can define arithmetic operations on Zm, the set of nonnegative integers less than m, that is, the set {0,1,…,m−1}. In particular, we define addition of these integers, denoted by +m, by a+mb=(a+b)modm, where the addition on the right-hand side of this equation is the ordinary addition of integers, and we define multiplication of these integers, denoted by ⋅m, by a⋅mb=(a⋅b)modm, where the multiplication on the right-hand side of this equation is the ordinary multiplication of integers. The operations +m and ⋅m are called addition and multiplication modulo m and when we use these operations, we are said to be doing arithmetic modulo m.
Use the definition of addition and multiplication in Zm to find 7+119 and 7⋅119.
Solution: Using the definition of addition modulo 11, we find that 7+119=(7+9)mod11=16mod11=5, and 7⋅119=(7⋅9)mod11=63mod11=8. Hence 7+119=5 and 7⋅119=8. ◀
The operations +m and ⋅m satisfy many of the same properties of ordinary addition and multiplication of integers. In particular, they satisfy these properties:
These properties follow from the properties we have developed for congruences and remainders modulo m, together with the properties of integers; we leave their proofs as Exercises 42–44.
Note that we have listed the property that every element of Zm has an additive inverse, but no analogous property for multiplicative inverses has been included. This is because multiplicative inverses do not always exist modulo m. For instance, there is no multiplicative inverse of 2 modulo 6, as the reader can verify. We will return to the question of when an integer has a multiplicative inverse modulo m later in this chapter.