








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









These notes cover concepts from elementary number theory.
We’ve now covered most of the basic techniques for writing proofs. So we’re going to start applying them to specific topics in mathematics, starting with number theory.
Number theory is a branch of mathematics concerned with the behavior of integers. It has very important applications in cryptography and in the design of randomized algorithms. Randomization has become an increasingly important technique for creating very fast algorithms for storing and retriev- ing objects (e.g. hash tables), testing whether two objects are the same (e.g. MP3’s), and the like. Much of the underlying theory depends on facts about which numbers evenly divide one another and which numbers are prime.
You’ve undoubtedly seen some of the basic ideas (e.g. divisibility) somewhat informally in earlier math classes. However, you may not be fully clear on what happens with special cases, e.g. zero, negative numbers. We also need clear formal definitions in order to write formal proofs. So, let’s start with
Definition: Suppose that a and b are integers. Then a divides b if b = an for some integer n. a is called a factor or divisor of b. b is called a multiple of a.
The shorthand for a divides b is a | b. Be careful about the order. The divisor is on the left and the multiple is on the right.
Some examples:
A number p is even exactly when 2 | p. The fact that zero is even is just a special case of the fact that zero is divisible by any integer.
3 Direct proof with divisibility
We can prove basic facts about divisibility in much the same way we proved basic facts about even and odd.
Claim 1 For any integers a,b,and c, if a | b and a | c then a | (b + c).
Proof: Let a,b,and c and suppose that a | b and a | c. Since a | b, there is an integer k such that b = ak (definition of divides). Similarly, since a | c, there is an integer j such that
5 Prime numbers
We’re all familiar with prime numbers from high school. Firming up the details:
Definition: an integer q ≥ 2 is prime if the only positive factors of q are q and 1. An integer q ≥ 2 is composite if it is not prime.
For example, among the integers no bigger than 20, the primes are 2, 3, 5, 7, 11, 13, 17, and 19.
A key fact about prime numbers is
Fundanmental Theorem of Arithmetic: Every integer ≥ 2 can be written as the product of one or more prime factors. Except for the order in which you write the factors, this prime factorization is unique.
The word “unique” here means that there is only one way to factor each integer.
For example, 260 = 2 · 2 · 5 · 13 and 180 = 2 · 2 · 3 · 3 · 5.
We won’t prove this theorem right now, because it requires a proof tech- nique called “induction,” which we haven’t seen yet.
There are quite fast algorithms for testing whether a large integer is prime. However, even once you know a number is composite, algorithms for factoring the number are all fairly slow. The difficulty of factoring large composite numbers is the basis for a number of well-known cryptographic algorithms (e.g. the RSA algorithm).
6 There are infinitely many prime numbers
We can now prove a classic result about prime numbers. So classic, in fact, that it goes back to Euclid, who lived around 300 B.C.
Euclid’s Theorem: There are infinitely many prime numbers.
This is a lightly disguised type of non-existence claim. The theorem could be restated as “there is no largest prime” or “there is no finite list of all primes.” So this is a good situation for applying proof by contradiction.
Proof: Suppose not. That is, suppose there were only finitely many prime numbers. Let’s call them p 1 , p 2 , up through pn. Consider Q = p 1 p 2 · · · pn + 1. If you divide Q by one of the primes on our list, you get a re- mainder of 1. So Q isn’t divisible by any of the primes p 1 , p 2 , up through pn. However, by the Fundamental Theorem of Arith- metic, Q must have a prime factor (which might be either itself or some smaller number). This contradicts our assumption that p 1 , p 2 ,... pn was a list of all the prime numbers.
Notice one subtlety. We’re not claiming that Q must be prime. Rather, we’re making the much weaker claim that Q isn’t divisible by any of the first n primes. It’s possible that Q might be divisible by another prime larger than pn.
7 GCD and LCM
If c divides both a and b, then c is called a common divisor of a and b. The largest such number is the greatest common divisor of a and b. Shorthand for this is gcd(a, b).
You can find the GCD of two numbers by inspecting their prime factor- izations and extracting the shared factors. For example, 70 = 2 · 5 · 7 and 130 = 2 · 5 · 13. So gcd(70, 130) is 2 · 5 = 10.
Similarly, a common multiple of a and b is a number c such that a|c and b|c. The least common multiple (lcm) is the smallest positive number for which this is true. The lcm can be computed using the formula:
Claim 4 For any integers a, b, q and r, where b is positive, if a = bq + r, then gcd(a, b) = gcd(b, r).
Proof: Suppose that n is some integer which divides both a and b. Then n divides bq and so n divides a − bq. (E.g. use various lemmas about divides from last week.) But a − bq is just r. So n divides r. By an almost identical line of reasoning, if n divides both b and r, then n divides a. So, the set of common divisors of a and b is exactly the same as the set of common divisors of b and r. But gcd(a, b) and gcd(b, r) are just the largest numbers in these two sets, so if the sets contain the same things, the two gcd’s must be equal.
If r is the remainder when a is divided by b, then a = bq + r, for some integer q. So we can immediately conclude that:
Corollary: Suppose that a and b are integers and b is positive. Let r be the remainder when a is divided by b. Then gcd(a, b) = gcd(b, r).
The term “corollary” means that this fact is a really easy consequence of the preceding claim.
9 Euclidean algorithm
We can now give a fast algorithm for computing gcd, which dates back to Eu- clid. Suppose that remainder(a, b) returns the remainder when a is divided by b. Then we can compute the gcd as follows:
gcd(a,b: positive integers) x := a y := b while (y > 0)
begin r := remainder(x,y) x := y y := r end return x
Let’s trace this algorithm on inputs a = 105 and b = 252. Traces should summarize the values of the most important variables.
x y r = remainder(x, y) 105 252 105 252 105 42 105 42 21 42 21 0 21 0 Since x is smaller than y, the first iteration of the loop swaps x and y. After that, each iteration reduces the sizes of a and b, because a mod b is smaller than b. In the last iteration, y has gone to zero, so we output the value of x which is 21.
To verify that this algorithm is correct, we need to convince ourselves of two things. First, it must halt, because each iteration reduces the magnitude of y. Second, by our corollary above, the value of gcd(x, y) does not change from iteration to iteration. Moreover, gcd(x, 0) is x, for any non-zero integer x. So the final output will be the gcd of the two inputs a and b.
This is a genuinely very nice algorithm. Not only is it fast, but it involves very simple calculations that can be done by hand (without a calculator). It’s much easier than factoring both numbers into primes, especially as the individual prime factors get larger. Most of us can’t quickly see whether a large number is divisible by, say, 17.
10 Pseudocode
Notice that this algorithm is written in pseudocode. Pseudocode is an ab- stracted type of programming language, used to highlight the important
numbers and addition “wraps around” from the highest number to the lowest one. This is true, for example, for the 12 hours on a standard US clock: 3 hours after 11 o’clock is 2 o’clock, not 14 o’clock.
The formal mathematical definitions of modular arithmetic are based on the notion of congruence. Specifically, two integers are “congruent mod k” if they differ by a multiple of k. Formally:
Definition: If k is any positive integer, two integers a and b are congruent mod k (written a ≡ b (mod k)) if k | (a − b).
Notice that k | (a − b) if and only if k | (b − a). So it doesn’t matter which number is subtracted from the other.
For example:
Congruence mod k is a relaxation of our normal rules for equality of numbers, in which we agree that certain pairs of numbers will be considered interchangeable.
13 Proofs with congruence mod k
Let’s try using our definition to prove a simple fact about modular arithmetic:
Claim 5 For any integers a, b, c, d, and k, k positive, if a ≡ b (mod k) and c ≡ d (mod k), then a + c ≡ b + d (mod k).
Proof: Let a, b, c, d, and k be integers with k positive. Suppose that a ≡ b (mod k) and c ≡ d (mod k). Since a ≡ b (mod k), k | (a − b), by the definition of congruence mod k. Similarly, c ≡ d (mod k), k | (c − d). Since k | (a − b) and k | (c − d), we know by a lemma about divides (above) that k | (a − b) + (c − d). So k | (a + c) − (b + d) But then the definition of congruence mod k tells us that a + c ≡ b + d (mod k).
This proof can easily be modified to show that
Claim 6 For any integers a, b, c, d, and k, k positive, if a ≡ b (mod k) and c ≡ d (mod k), then ac ≡ bd (mod k).
So standard arithmetic operations interact well with our relaxed notation of equality.
14 Equivalence classes
The true power of modular conguence comes when we gather up a group of conguent numbers and treat them all as a unit. Such a group is known as a congruence class or an equivalence class. Specifically, suppose that we fix a particular value for k. Then, if x is a number, the equivalence class of x (written [x]) is the set of all numbers congruent to x mod k.
For example, suppose that we fix k to be 7. Then
People making extensive use of modular arithmetic frequently drop the square brackets. We’re keeping the brackets for the moment to help you un- derstand more clearly how the modular integers are created from the normal integers.
15 Wider perspective on equivalence
Modular arithmetic is often useful in describing periodic phenomena. For example, hours of the day form a circular space that is Z 12. However, the tradition in time-keeping is to prefer the names [1], [2],... , [12] rather than the [0], [2],... , [11] traditional in math.
Low-precision integer storage on computers frequently uses modular arith- metic. For example, values in digitized pictures are often stored as 8-bit unsigned numbers. These numbers range from 0 to 255, i.e. the structure is Z 256. In Z 256 , if you add [17] to [242], the result will be [3].
Equivalence classes of a more general type are used to construct rational numbers. That is, rational numbers are basically fractions, except that two fractions x y and p q are considered equivalent if xq = py. So, for example, the
set [^23 ] would contain values such as 23 , 69 , and − −^46. Most people prefer to name a rational number using a fraction in lowest terms.
Further afield, notice that musicians have more than one name for each note. There are seven note names, each of which can be sharped or flatted. However, there are only 12 different notes in a standard Western scale: many of these 21 names actually refer to the same note.^1 For example, A# is the same note as Bb. So, using more mathematical notation than the musicians would find comfortable, we could say that [A#] contains both A# and Bb.
(^1) More precisely, this is true on instruments like pianos. More subtle note distinctions
are possible on some other instruments.
16 Variation in Terminology
In these notes, a divides b is defined to be true if b = an for some integer n. There is some variation among authors as to what happens when a is zero. Clearly, a non-zero number can’t be a multiple of zero. But is zero a multiple of itself? According to our definition, it is, but some authors explicitly exclude this special case. Fortunately, this is a special case that one rarely sees in practice. The greatest common divisor is also known as the highest common factor (HCF).
In the shorthand notation a ≡ b (mod k), the notation (mod k) is log- ically a modifier on our notion of equality (≡). In retrospect, it might have made more sense to write something like a ≡k b. However, a ≡ b (mod k) has become the standard notation and we have to live with it.
There are many variant notations for the quotient and remainder cre- ated by integer division, particularly if you include the functions built in to most programming languages. Popular names for the remainder include mod, modulo, rem, remainder, and %. The behavior on negative inputs dif- fers from language to language and, in some cases, from implementation to implementation.^2 This lack of standardization often results in hard-to-find program bugs.
Some authors use Z/nZ instead of Zn as the shorthand name for the inte- gers mod n. The notation Zn may then refer to a set which is structurally the same as the integers mod n, but in which multiplication and exponentiation are used as the basic operations, rather than addition and multiplication. The equivalence class of n is sometimes written n.
(^2) The “modulo operation” entry on wikipedia has a nice table of what happens in different languages.