Number Theory Course notes for MA 341, Spring 2018
Jared Weinstein
May 2, 2018
Contents
1 Basic properties of the integers 3 1.1 Definitions: Z and Q ...... 3 1.2 The well-ordering principle ...... 5 1.3 The division algorithm ...... 5 1.4 Running times ...... 6 1.5 The Euclidean algorithm ...... 8 1.6 The extended Euclidean algorithm ...... 10 1.7 Exercises due February 2...... 11
2 The unique factorization theorem 12 2.1 Factorization into primes ...... 12 2.2 The proof that prime factorization is unique ...... 13 2.3 Valuations ...... 13 2.4 The rational root theorem ...... 15 2.5 Pythagorean triples ...... 16 2.6 Exercises due February 9 ...... 17
3 Congruences 17 3.1 Definition and basic properties ...... 17 3.2 Solving Linear Congruences ...... 18 3.3 The Chinese Remainder Theorem ...... 19 3.4 Modular Exponentiation ...... 20 3.5 Exercises due February 16 ...... 21
1 4 Units modulo m: Fermat’s theorem and Euler’s theorem 22 4.1 Units ...... 22 4.2 Powers modulo m ...... 23 4.3 Fermat’s theorem ...... 24 4.4 The φ function ...... 25 4.5 Euler’s theorem ...... 26 4.6 Exercises due February 23 ...... 27
5 Orders and primitive elements 27 5.1 Basic properties of the function ordm ...... 27 5.2 Primitive roots ...... 28 5.3 The discrete logarithm ...... 30 5.4 Existence of primitive roots for a prime modulus ...... 30 5.5 Exercises due March 2 ...... 32
6 Some cryptographic applications 33 6.1 The basic problem of cryptography ...... 33 6.2 Ciphers, keys, and one-time pads ...... 33 6.3 Diffie-Hellman key exchange ...... 34 6.4 RSA ...... 36
7 Quadratic Residues 37 7.1 Which numbers are squares? ...... 37 7.2 Euler’s criterion ...... 38 7.3 Exercises due March 16 ...... 40
8 Quadratic Reciprocity 40 8.1 The Legendre symbol ...... 40 8.2 Some reciprocity laws ...... 41 8.3 The main quadratic reciprocity law ...... 42 8.4 The Jacobi symbol ...... 44 8.5 Exercises due March 23 ...... 45
9 The Gaussian integers 46 9.1 Motivation and definitions ...... 46 9.2 The division algorithm and the gcd ...... 48 9.3 Unique factorization in Z[i]...... 49 9.4 The factorization of rational primes in Z[i]...... 49 9.5 Exercises due March 30 ...... 50
2 10 Unique factorization and its applications 51 10.1 Pythagorean triples, revisited ...... 51 10.2 A cubic Diophantine√ equation ...... 51 10.3 The system Z[ −2] ...... 52 10.4 Examples of the failure of unique factorization ...... 53 10.5 The Eisenstein integers ...... 54 10.6 Exercises due April 13 ...... 56
11 Some analytic number theory 57 P 11.1 p 1/p diverges ...... 58 11.2 Classes of primes, and their infinitude ...... 60 P 11.3 p≡±1 (mod 4) 1/p diverges ...... 61 11.4 Exercises due April 20 ...... 63
12 Continued fractions and Pell’s equation 64 12.1 A closer look at the Euclidean algorithm ...... 64 12.2 Continued fractions in the large ...... 67 12.3 Real quadratic irrationals√ and their continued fractions . . . 68 12.4 Pell’s equation and Z[ d]...... 70 12.5 The fundamental unit ...... √ ...... 71 12.6 The question of unique factorization for Z[ d]...... 73 12.7 Exercises due April 27 ...... 74
13 Lagrange’s four square theorem 74 13.1 Hamiltonian quaternions ...... 75 13.2 The Lipschitz quaternions ...... 77 13.3 The Hurwitz quaternions ...... 78 13.4 Hurwitz primes ...... 80 13.5 The end of the proof ...... 81
1 Basic properties of the integers
1.1 Definitions: Z and Q Number theory is the study of the integers: ..., −3, −2, −1, 0, 1, 2, 3,... We use the symbol Z to stand for the set of integers. (Z stands for German Zahl, meaning number.) Now might be a good time to review some set- theoretic notations: 3 ∈ √Z is a true statement, meaning that 3 is a member of the integers, whereas 7 6∈ Z.
3 We observe that integers can be added, subtracted, and multiplied to produce other integers, but the same cannot be said for division. When we divide integers we create rational numbers, such as 3/7 and −2/3. We write the set of rational numbers as Q, for quotient. The failure of integers to divide each other evenly is so important that we have special notation to express it: for integers a and b, we write a|b to mean that b/a is an integer. In other words, a|b means that there exists c ∈ Z such that b = ac. In this case we say that a is a divisor of b, and that b is a multiple of a.
Example 1.1.1. The divisors of 12 are 1,2,3,4,6,12 and their negatives. A divisor of a positive integer n is proper if it’s positive and not equal to n itself. Thus the proper divisors of 12 are just 1,2,3,4,6.
Example 1.1.2. 1 is a divisor of every integer, as is −1. Also, every integer divides 0, since 0 = 0 · a for every a. However, the only multiple of 0 is 0 itself.
Proposition 1.1.3. Suppose that a, b, c ∈ Z. If a|b and b|c, then a|c.
Proof. There exists integers m, n such that b = am and c = bn. Then c = amn, so a|c.
The above proposition says that the relation a|b is transitive.
Proposition 1.1.4. Suppose a, b, d, x, y ∈ Z. If d|a and d|b, then d|ax + by.
We remark that ax + by is called a linear combination of a and b.
Proof. Write a = dm and b = dn, then ax+by = d(mx+ny), so d|ax+by.
A positive integer is prime if it has no proper divisors other than 1. By convention, 1 is not counted as prime.
Theorem 1.1.5 (Euclid). There are infinitely many primes.
Proof. If there we finitely many primes, then we could list all of them as 1 p1, . . . , pn. The number N = p1 ··· pn + 1 is divisible by some prime , which must be one of our enumerated primes, say pi. Then pi|N but also pi|p1 ··· pn. Thus pi|(N − p1 ··· pn) = 1, which is absurd.
1Strictly speaking, we don’t know this fact yet, but for now we’ll take it for granted.
4 Therefore we are guaranteed to never run out of primes. As of January 2018 the largest known prime is
277,232,917 − 1.
This is a Mersenne prime, meaning a prime which is one less than a power of two. It is not known if there are infinitely many Mersenne primes.
1.2 The well-ordering principle How do we know that every integer n > 1 is divisible by a prime? An argument might go this way: if n isn’t itself prime, then it has a proper divisor n1 > 1. If n1 isn’t prime, then it has a proper divisor n2 > 1, and so on. The result is that we get a strictly decreasing sequence of positive integers n > n1 > n2 > . . . , which cannot go on indefinitely. This fact, obvious that it may be, is quite important. We give it a name: The well- ordering principle.
Axiom 1.2.1 (The well-ordering principle). 2 A strictly decreasing sequence of positive integers cannot go on indefinitely.
Rather than attempt to prove this statement, we take it as an axiom of the system of integers.
1.3 The division algorithm We noted before that the integers are not closed under division. But there is a familiar operation among integers: you can divide one by another to obtain a quotient and a remainder. For instance, when 39 is divided by 5, the quotient is 7 and the remainder is 4. We can check this by verifying that 39 = 5 · 7 + 4. When this is done, the remainder must be less than the number you divided by. It would be incorrect to say that 5 goes into 39 with a quotient of 6 and a remainder of 9, even though 39 = 5 · 6 + 9 is also true.
Theorem 1.3.1 (The division algorithm). Let a, b ∈ Z, with b > 0. There exists a unique pair of integers q, r ∈ Z such that a = bq + r and that 0 ≤ r < b.
Of course, if the remainder r is 0, then a = bq and therefore b|a.
2There is another formulation: every nonempty subset of the positive integers has a least element. The two formulations are equivalent.
5 Proof. We’ll assume that a is positive, the other cases are similar. Consider the sequence a, a − b, a − 2b, a − 3b, . . . . By the well-ordering principle, these cannot all be nonnegative integers. So there is a least one which is nonnegative, call it r = a − bq. If r > b, then a − b(q + 1) = r − b > 0, which contradicts our assumption that r was the least element of our sequence. Therefore r ≤ b. That handles the existence part of the theorem. For uniqueness: if there were another pair q0, r0 such that a = bq + r = bq0 + r0, then r − r0 = b(q0 − q) would be a multiple of b, but since 0 ≤ r, r0 < b, this can only happen if r = r0, which implies q = q0 as well.
This proof gives a hint to the “algorithm” part of the division algorithm: to divide 5 into 39, keep subtracting 5 from 39 to get 34, 29, 24, 19, 14, 9, 4, at which point we cannot subtract anymore and 4 is the remainder. One says that just as multiplication is repeated addition, division is repeated subtraction. I want to introduce an important piece of notation: if r is the remainder when b is divided into a, we sometimes write a mod b = r, especially if the remainder is all we care about. You already do this with time: 17 hours after 2 o’clock is 19 mod 12 = 7 o’clock. (Or substitute 24 for 12 if you use that system.) We say that r is the residue of a modulo b. It is always between 0 and b − 1 inclusive.
1.4 Running times Of course in practice when you want to divide larger numbers, like 114 into 395623945, you don’t subtract repeatedly at all. Instead you perform an
6 algorithm known as long division, which looks like this:
3470385 114 395623945 342000000 53623945 45600000 8023945 7980000 43945 34200 9745 9120 625 570 55 Thus the quotient is 3470385 and the remainder is 55. This may look labo- rious, but you could probably do it by hand in just a few minutes. Contrast this with the repeated subtraction method. You would have had to subtract 114 from 395623945 a total of 3470385 times – even if you could do one subtraction every second, it would take 40 days! In our applications to cryptography, it will be important to keep track of how long it takes for a person (or a computer) to run a particular algo- rithm, in terms of how many basic operations are performed as a function of how long the inputs are. In the case of our long division problem, there were 3 + 9 = 12 inputs (the total number of digits in 114 and 395623945). If a basic operation means adding, subtracting, or multiplying individual digits, then the long division algorithm took dozens of operations, while the repeated subtraction algorithm took millions of operations. One says that long division is a polynomial time algorithm, but repeated subtraction is exponential time. Behind any abstract theorem in number theory there is often an algorith- mic question. For instance, we just saw that every integer n > 1 has a prime divisor. Is there a fast algorithm to find one? One simple method is to try dividing 2, 3, 4, . . . , n − 1, n into n to see if any of these are divisors; the first one that divides n evenly will be prime (why?). Such an algorithm would require at least n steps. When n has hundreds of digits, this is completely impractical. √ We can save some time by noting that if we reach n without finding any factors, then n must be prime, which limits the number of steps to
7 √ about n. That seems like it should help a lot, until you figure that if n √ has 200 digits, then n has about 100. Computers these days are fast, but no computer out there can execute 10100 steps in any reasonable amount of time.
1.5 The Euclidean algorithm Given positive integers a and b, a common divisor is an integer d such that d|a and d|b. The greatest common divisor (gcd) is of course the greatest of these. This comes up in simplifying fractions: to reduce 18/12 you have to divide both numerator and denominator by their gcd, which is 6, to get 3/2. If gcd(a, b) = 1, we say that a and b are relatively prime or coprime. If a and b are large numbers, how do we compute gcd(a, b)? One way to be to count down from the smaller of the two numbers, and stop at the first one which divides them both. But if the smaller number has 100 digits, then this process will take about 10100 steps, which is far too long. The Euclidean algorithm is a very efficient way to compute gcd(a, b) with- out having to factor either number. It rests on repeated application of the division algorithm (which we already noted runs in polynomial time). It’s best illustrated by example. Suppose we want gcd(119, 259). We calculate:
259 = 2 · 119 + 21 119 = 5 · 21 + 14 21 = 1 · 14 + 7 14 = 2 · 7 + 0.
Note that in each iteration, the denominator and remainder become the numerator and denominator in the next step. The last non-zero remainder is 7, which is the gcd we wanted! The algorithm works because of the following lemma: Lemma 1.5.1. For integers a, b, q, r with a = bq + r, we have gcd(a, b) = gcd(b, r). Proof. Let d = gcd(a, b) and e = gcd(b, r). We’ll show that d ≤ e and e ≤ d, which will do the trick. First let’s show that d ≤ e. Since d divides a and b, it divides r = a − bq, which is a linear combination of a and b. Thus d is a common divisor of b and r. Therefore it cannot exceed the greatest common divisor of b and r, which is e.
8 Now let’s show that e ≤ d. Since e divides b and r, it divides a = bq + r, which is a linear combination of b and r. Thus e is a common divisor of a and b. Therefore it cannot exceed the greatest common divisor of a and b, which is d.
Thus in the example, gcd(259, 119) = gcd(119, 21) = gcd(21, 14) = gcd(14, 7) = gcd(7, 0) = 7. I should note here that as long as the remainder is nonzero, the algorithm can continue to produce a smaller remainder. By the well-ordering principle, the remainders cannot decrease forever, and so eventually one arrives at a remainder of 0. Finally, note that gcd(r, 0) = r for any nonzero r. It turns out that Euclid’s algorithm runs in polynomial time. Computers can easily compute gcd(a, b) even if a and b have hundreds of digits. To get a sense of why Euclid’s algorithm runs quickly, let us examine the following worst case scenario, in which we compute gcd(55, 34):
55 = 1 · 34 + 21 34 = 1 · 21 + 13 21 = 1 · 13 + 8 13 = 1 · 8 + 5 8 = 1 · 5 + 3 5 = 1 · 3 + 2 3 = 1 · 2 + 1 2 = 2 · 1 + 0
We computed gcd(55, 34) = 1 in 8 iterations, whereas gcd(259, 119) = 7 took only 4. Notice that the quotient was 1 each time we divided (ex- cept the last one), which means that the remainders go down as slowly as possible. We got this result because we used consecutive numbers in the Fibonacci sequence 1, 1, 2, 3, 5, 8,... , in which each number is the sum of the two previous numbers. As a result, computing gcd(a, b) can be done in at most n iterations, where the nth number in the Fibonacci sequence is larger than a and b.
9 1.6 The extended Euclidean algorithm The integers 49 and 40 are relatively prime, so it’s no surprise that the Euclidean algorithm produces 1:
49 = 1 · 40 + 9 40 = 4 · 9 + 4 9 = 2 · 4 + 1 4 = 4 · 1 + 0
Now look at the sequence of quotients: 1, 4, 2, 4. It turns out that this sequence “encodes” the numbers we started with. Place them in the top row of a table like so: 1 4 2 4 1 0 0 1 Proceeding from left to right, we fill in the blanks as follows. The first num- ber of the top row is 1. Use the two numbers in the second row immediately preceeding this column to make a number like this: 1 · 0 + 1 = 1. Then 4 · 1 + 0 = 4, so we put that in the next spot. Filling out everything like this gives us 1 4 2 4 1 0 1 4 9 40 0 1 1 5 11 49 The final column has 40, 49, which of course are the numbers we started with. The second-to-last column has 31, 38. Observe that
49 · 31 − 40 · 38 = 1.
This method, called the extended Euclidean algorithm, gives a practical means of finding a solution to the equation
ax + by = 1 when gcd(a, b) = 1. Now let’s try a = 259 and b = 119, like in our previous example. The sequence of quotients is 2, 5, 1, 2 and the gcd is 7. The extended Euclidean algorithm gives us
10 2 5 1 2 1 0 1 5 6 17 0 1 2 11 13 37 The numbers in the last column are 17 = 119/7 and 37 = 259/7. That is, we got the numbers we started with, divided out by their gcd. The second-to-last column has 6 and 13, and
37 · 6 − 17 · 13 = 1, and multiplying both sides by 7 gives
259 · 6 − 119 · 13 = 7.
Theorem 1.6.1 (Bezout’s identity). Let a and b be positive integers. There exist integers x, y such that ax + by = gcd(a, b). Proof. If you believe that the extended Euclidean algorithm works, you may be satisfied already. But here is an independent proof: Among all posi- tive linear combinations ax + by, there is a smallest one, say ax + by = d. Certainly gcd(a, b)|d. Let’s perform the division algorithm with a and d: a = dq + r, with 0 ≤ r < d. Then
r = a − dq = a − (ax + by)q = a(1 − xq) − bqy is also a linear combination of a and b. Since d was assumed least among all positive linear combinations, and r < d, the only way this is possible is if r = 0. Thus d|a. Similarly d|b, which means d ≤ gcd(a, b). Combining this with gcd(a, b)|d gives d = gcd(a, b).
1.7 Exercises due February 2. 1. The proper divisors of 6 are 1,2,3. We have 1 + 2 + 3 = 6, meaning that 6 is a perfect number. Verify that 28 and 496 are also perfect.
2. The ancient Greeks divided integers n into perfect (sum of proper divisors is n), abundant (sum of divisors is > n), and deficient (sum of divisors is < n). Classify each of the numbers 2, 3,..., 20 into one of these three classes.
3. Suppose that p = 2n − 1 is a Mersenne prime. Prove that 2n−1p is a perfect number.
4. Prove that if a, b, c, d ∈ Z and a|b and c|d, then ac|bd.
11 5. Let p1, . . . , pn be distinct primes. How many positive divisors does p1 ··· pn have? 6. True or false: the rational numbers Q obey the well-ordering principle. Explain your reasoning.
7. What is the remainder when 2100 is divided by 5? (Find a pattern in the first few powers of 2.)
8. Use the Euclidean algorithm to compute gcd(527, 408) and gcd(1001, 121).
9. Use the extended Euclidean algorithm to find integers x and y such that 527x + 408y = gcd(527, 408).
10. Let a and b be integers. Show that any common divisor of a and b must divide gcd(a, b).
2 The unique factorization theorem
2.1 Factorization into primes Lemma 2.1.1. Every positive integer can be expressed as a product of primes.
(Even 1 is a product of primes: it is the empty product, so to speak. And 17 is a product of primes too, but just one of them. So one must interpret the lemma to mean “every positive integer can be expressed as a product of zero or more primes.”)
Proof. Let n ∈ Z be positive. If n = 1, we’re done. Otherwise we can find a prime divisor p1|n. Write n = p1n1, where n1 < n. If n1 = 1, we’re done. Otherwise we can find a prime divisor p2|n1; write n1 = p2n2, with n2 < n1. Continuing, we get a sequence of descending positive integers n > n1 > n2 > . . . , which cannot go on forever. Thus there exists t for which nt = 1, and then n = p1p2 ··· pn. The proof even suggests a sort of algorithm for factoring a number into primes: keep dividing out prime factors until you’re completely factored the number. For instance,
72 = 2 · 36 = 2 · 2 · 18 = 2 · 2 · 2 · 9 = 2 · 2 · 2 · 3 · 3 = 23 · 32.
12 The process produces the same result no matter how we factor the num- ber. Here’s another way:
72 = 3 · 24 = 3 · 3 · 8 = 3 · 3 · 2 · 4 = 3 · 3 · 2 · 2 · 2 = 23 · 32.
Perhaps this isn’t so surprising. But how do we really know that you get the same prime factorization no matter what? Could there be a particular num- ber n, possibly with hundreds of digits, which has two prime factorizations n = p1p2 = q1q2, with all four primes p1, p2, q1, q2 distinct?
2.2 The proof that prime factorization is unique All will rest upon the following lemma.
Lemma 2.2.1. Let a, b, c ∈ Z, with a|bc and (a, b) = 1. Then a|c.
Proof. Crucially, we use Bezout’s identity (Theorem 1.6.1). There exist x, y ∈ Z with ax + by = 1. Multiplying by c, we get acx + bcy = c. We have a|bc, so that a|bcy. Obviously a|acx, so a|acx + bcy = c.
Corollary 2.2.2. Let a, b ∈ Z. If p is a prime number and p|ab, then p|a or p|b.
Proof. We will show that if p - a then p|b. If p - a, then gcd(p, a) = 1, in which case the preceeding lemma shows that p|b.
From this it is easy to see that if p divides an arbitrary product then p must divide one of the factors.
Theorem 2.2.3 (Unique Factorization Theorem). Every positive integer can be written as a product of primes in a unique way, up to ordering.
Proof. If p1 ··· pt = q1 ·qs for primes p1, ··· , pt, q1, ··· , qs, then pt divides the product q1 ··· qs, so that it must divide one of the factors. Without loss of generality, pt|qs. But these are primes, so we must have pt = qs. Removing this factor gives p1 ··· pt−1 = q1 ··· qs−1. Continuing, we are able to match up each p with a q until no further factors remain.
2.3 Valuations The Unique Factorization Theorem shows that every n ≥ 1 can be written Y n = pap , p
13 where p runs over primes and ap is a nonnegative integer. It must be the case that ap = 0 for all but finitely many primes, so that the product can make sense. Since prime factorization is unique, the ap are uniquely determined by n, and so it makes sense to define
valp(n) = ap, 2 the valuation of n at p. For instance, 75 = 3 · 5 , so val3(75) = 1 and val5(75) = 2, whereas valp(75) = 0 for every other prime p. You can extend this definition to include negative n as well: valp(−n) = valp(n). You can even extend it to include 0. We set valp(0) = ∞. (Why is this the right definition?) The function valp obeys the following rules:
valp(mn) = valp(m) + valp(n) k valp(m ) = k valp(m), which makes it similar to the logarithm to base p. Here are some basic facts about valp: Theorem 2.3.1. Let a, b ∈ Z.
1. a|b if and only if, for all primes p, valp(a) ≤ valp(b).
2. valp(gcd(a, b)) = min {valp(a), valp(b)} .
3. valp(lcm(a, b)) = max {valp(a), valp(b)} . 4. If a > 0, then a is a perfect kth power if and only if, for all primes p, k| valp(a). I encourage you think about why these facts are true, and to work with some examples. For instance, the gcd of 25 · 3 · 54 and 32 · 53 is 3 · 53.A consequence of (2) is that gcd(a, b) = 1 if and only if, for all primes p, either valp(a) or valp(b) is 0. Theorem 2.3.2. For a, b ∈ Z positive, gcd(a, b) lcm(a, b) = ab.
Proof. The valp of the left hand side is min {valp(a), valp(b)}+max {valp(a), valp(b)} = valp(a) + valp(b) (why?), which is the same as valp(ab). Theorem 2.3.3. Let a and b be coprime positive integers. If ab is a perfect square, then so are a and b.
Proof. Since ab is a perfect square, valp(ab) = valp(a) + valp(b) is even for all p. Then since one of valp(a) and valp(b) has to be 0, both must be even. This shows by point (4) above that a and b are perfect squares.
14 2.4 The rational root theorem This is a classic example of proof by contradiction. √ Theorem 2.4.1. 2 is irrational. √ √ Proof. Assume that 2 is rational. Then 2 = p/q for positive p, q ∈ Z. Then p2 = 2q2. Since 2|p2, Theorem [?] shows that 2|p; i.e. p is even. Write 2 2 p = 2p0; then p0 = 2q . The same reasoning shows that q is even. Write 2 2 q = 2q0, and then p0 = 2q0. But this is the original equation! Repeating the process gives a descending sequence of positive integers p > p0 > p1 > . . . , which is impossible.
It may have occurred to you to avoid the use of the well-ordering principle in this proof by arguing as follows: express p/q in lowest terms, show that p and q are both even, and then draw a contradiction. To do this, though, we need to know that it is possible to expression in lowest terms in the first place! This is the point of the following theorem: Theorem 2.4.2. If gcd(p, q) = d, then gcd(p/d, q/d) = 1. Then if p/q is a rational number, we can let d = gcd(p, q), and then after writing p = dp0 and q = dq0, then gcd(p0, q0) = 1, and p0/q0 is in lowest terms.
Proof. We can write px + qy = d for some integers x and y, and then p0x + q0y = 1, which shows that gcd(p0, q0) = 1.
But let’s return to the subject√ of irrationality. A variation of the above proof can be used to show that 3 and 71/3 are irrational too. These are examples of algebraic numbers, a class of complex numbers which include √ √ p √ combinations like 2 + 3, 3 + 7 − 2. A number is algebraic if it is the root of a polynomial with integer coefficients. Theorem 2.4.3 (Rational Root Theorem). Suppose the polynomial
n n−1 f(x) = anx + an−1x + ··· + a0 has coefficients ai ∈ Z. If p/q is a fraction in lowest terms which is a root of f(x), then q|an and p|a0. Proof. The fact that p/q is a root of f(x) means that f(p/q) = 0. After clearing away denominators, this becomes
n n−1 n−1 n anp + an−1p q + ··· + a1pq + a0q = 0.
15 Since p divides all terms other than the last one, it divides the last one as n well: p|a0q . But by Theorem 2.2.2, p|a0 (remember that gcd(p, q) = 1). The proof that q|an is similar. The Rational Root Theorem gives a method for finding all rational roots p/q of a polynomial with integer coefficients, since the possibilities for p√and q are limited. We can also√ use the Rational Root Theorem√ to show 2 is irrational in another way. 2 is a root of x2 − 2. If 2 = p/q in lowest terms, then p|2 and q|1, which implies that p/q = ±2. But this is nonsense, √ √ since 2 6= ±2! The same proof can be used to show that n is irrational whenever n is not a perfect square.
2.5 Pythagorean triples A pythagorean triple is a list (a, b, c) of integers which satisfy
a2 + b2 = c2, so that a, b, c could be the lengths of sides of a right triangle. This is an example of a Diophantine equation: a polynomial equation meant to be solved for integer variables. This particular Diophantine equation is truly old, the solution (3, 4, 5) being known to the ancient Egyptians. Other familiar solutions are (5, 12, 13) and (6, 8, 10). The point of this discussion is to find all the Pythagorean triples. Note that if a prime p divides two of the three numbers, then it divides the third (Theorem 2.2.2 again). Let’s call a triple primitive if gcd(a, b, c) = 1. Then in a primitive triple, all pairs (a, b), (a, c), (b, c) are coprime as well. It suffices to find all the primitive triples, because any other triplet is just a multiple of a primitive one. Suppose (a, b, c) is primitive. Then a and b can’t both be even. But they can’t both be odd either: if a = 2m+1 and b = 2n+1 are odd, then c = 2c0 is even, and substituting gives
2 2 2 4m + 4m + 1 + 4n + 4n + 1 = 4c0, or 2 2 2 2(m + m + n + n) + 1 = 2c0, which is impossible. So a and b have opposite parities. Without loss of generality, say a is odd and b is even. We have a2 = c2 − b2 = (c + b)(c − b).
16 Since gcd(b, c) = 1, gcd(c + b, c − b) is 1 or 2 (Exercise 3). But we can rule out 2, since (c + b)(c − b) = a2 is odd. Thus (c + b)(c − b) = a2 is odd, so in fact gcd(c+b, c−b) = 1. Now by Theorem 2.3.3, c+b = p2 and c−b = q2 for positive integers p, q. These have to be odd and relatively prime. Solving, we get c = (p2 + q2)/2, b = (p2 − q2)/2, and a = pq.
Theorem 2.5.1. As p and q run through pairs of odd coprime integers, (pq, (p2 − q2)/2, (p2 + q2)/2) runs through all primitive Pythagorean triples (up to switching the a and b coordinates).
2.6 Exercises due February 9 1. How many (positive) divisors does the number 25 · 37 · 5 · 116 have?
2. Prove that if a, b, c ∈ Z, then gcd(ab, ac) = a gcd(b, c).
3. Prove that if a, b ∈ Z are coprime then gcd(a + b, a − b) is either 1 or 2.
4. Let a, b, c ∈ Z. Prove that if gcd(a, b) = 1, a|c, and b|c, then ab|c.
5. Prove that if ab is a perfect cube and gcd(a, b) = 1, then a and b are both perfect cubes.
6. Find all rational roots of 3x3 + x2 + x − 2. √ √ 7. Prove that 2 + 3 is irrational.
8. Show that if a and b are integers and an|bn, then a|b. (There are multiple ways to do this. One quick way is to use the rational root theorem!)
9. When the number 30! is written out in base 10, how many zeros are at the end?
10. Is it possible to write 50 as the difference between two perfect squares?
3 Congruences
3.1 Definition and basic properties Definition 3.1.1. For integers a, b, m, we write a ≡ b (mod m) (pro- nounced: a is congruent to b modulo m) if m|a − b.
17 The notation here suggests that somehow a and b are equal in a funny way. Indeed you probably already have a notion of taking a number modulo 12 (or 24) when you think about the clock: The clock looks the same when 100 hours pass as when 4 hours pass, because 100 ≡ 4 mod 12. Or if you think about numbers as being even or odd: a ≡ b (mod 2) means that a and b have the same parity (they are either both odd or both even). The notion that a ≡ b (mod m) is a sort of equality can be formalized by checking the following three properties:
1. (Reflexivity) a ≡ a (mod m).
2. (Symmetry) If a ≡ b (mod m) then b ≡ a (mod m).
3. (Transitivity) If a ≡ b (mod m) and b ≡ c (mod m) then a ≡ c (mod m).
4. If a ≡ b (mod m) then:
a + c ≡ b + c (mod m) a − c ≡ b − c (mod m) ac ≡ bc (mod m)
The first three properties express the fact that ≡ is an equivalence relation. This means that you can treat the ≡ symbol much like the = symbol, at least when it comes to substituting equals for equals. The fourth property means that when it comes to congruences you can add, subtract or multiply by c on both sides and the congruence will remain true. You should be able to come up with short proofs of the above properties. For instance, here’s a proof of 4(a): If a ≡ b (mod m) it means that m|a−b = (a + c) − (b + c), so a + c ≡ b + c (mod m).
3.2 Solving Linear Congruences The rules we outlined above enable us to solve for x in congruences like
x + 3 ≡ 1 (mod 10).
Namely, you can subtract 3 from both sides to get x ≡ −2 (mod 10), which is the same as x ≡ 8 (mod 10). But if the equation is
3x ≡ 2 (mod 10),
18 we cannot “divide by 3” on both sides just yet because “1/3” doesn’t having any meaning modulo 10 (at least until we give it meaning). We can try plugging in x = 0, 1,..., 9 to see that there is just one solution x ≡ 4 (mod 10). Here’s another example: 2x ≡ 4 (mod 10). There’s the obvious solution x ≡ 2 (mod 10), but then there’s also x ≡ 7 (mod 10). Those are the only solutions modulo 10. You can also say that the complete solution is x ≡ 2 (mod 5). Finally, look at 2x ≡ 3 (mod 10). This time there are no solutions at all! Thus a linear congruence can have zero, one, or more than one solutions.
Theorem 3.2.1. The congruence ax ≡ b (mod m) has a solution if and only if gcd(a, m)|b. If a solution exists, then it is unique modulo m/ gcd(a, m). In particular if gcd(a, m) = 1 then a solution always exists and is unique modulo m.
Proof. Let’s begin with the case that gcd(a, m) = 1. Then there exist x, y ∈ Z with aX +mY = 1. But then m|mY = aX −1, so that aX ≡ 1 (mod m). We can multiply this by b to get a(bX) ≡ b (mod m). Therefore x = bX is a solution. If x0 is another solution, then ax ≡ ax0 (mod m), so m|a(x−x0). Since gcd(a, m) = 1, m|x − x0 and so x ≡ x0 (mod m). We have shown that the solution is unique in this case. In the general case, let d = gcd(a, m). The congruence ax ≡ b (mod m) means that m|ax − b. Since d|m and |a, we also have d|b. Thus shows that if there is a solution we must have d|b. Supposing then that d|b, let a = da0, b = db0 and m = dm0. The statement m|ax − b is equivalent to m0|a0x − b0, or a0x ≡ b0 (mod m0). But now gcd(a0, m0), so this new congruence has a unique solution modulo m0.
3.3 The Chinese Remainder Theorem This section is concerned with solving simultaneous congruences such as
x ≡ 2 (mod 7) x ≡ 5 (mod 6), where x needs to satisfy both congruences at the same time. We might proceed by listing the solutions to the first congruence: 2, 9, 16, 23,... and stopping at the first one that satisfies the second, which is 23. Here’s a
19 different one:
x ≡ 2 (mod 8) x ≡ 3 (mod 10).
This one does not have any solutions, since those x which satisfy the first congruence are even, and those satisfying the second congruence must be odd. First we’ll handle the situation that m and n are coprime.
Theorem 3.3.1. Let m and n be coprime integers. Then the system of congruences
x ≡ a (mod m) x ≡ b (mod n) has a unique solution modulo mn.
Proof. FIrst we’ll show that a solution exists, and then we’ll show it’s unique mod mn. Since m and n are coprime, there exist integers y and z such that my + nz = 1. Then my ≡ 1 (mod n) and nz ≡ 1 (mod m). So
x = anz + bmy satisfies x ≡ a (mod m) and x ≡ b (mod n). For uniqueness: if x0 is another solution, then x − x0 ≡ 0 (mod m) and x − x0 ≡ 0 (mod n). That is, x − x0 is divisible by m and n. Since m and n are relatively prime, x−x0 is divisible by mn, so that x ≡ x0 (mod mn).
The proof suggests a practical solution to the system of congruences: use the Extended Euclidean Algorithm to find y and z such that my + nz = 1, and then use the formula for x above. If m and n are not necessarily relatively prime, say d = gcd(m, n), then the simultaneous congruence cannot have a solution unless d|a − b.
3.4 Modular Exponentiation We have already remarked that the division algorithm runs very fast. The operation a (mod m) can be computed in polymomial time, so that it is reasonable to compute even if a and m have hundreds of digits. The same is true for modular exponentiation, meaning the computation of an (mod m). We demonstrate with the example of 3165 (mod 100). That
20 is, we want the last two digits of 3165. Certainly we could compute 3165 and simply write down the last two digits, but this is impractical when the exponent is very large. Instead, we write the exponent in binary:
165 = 27 + 25 + 22 + 1.
Now the idea is to square the base 7 repeatedly:
3 ≡ 3 (mod 100) 32 ≡ 9 2 32 ≡ 81 3 32 ≡ 61 4 32 ≡ 21 5 32 ≡ 41 6 32 ≡ 81 7 32 ≡ 61
Then
7 5 2 3165 = 32 · 32 · 32 · 3 ≡ 61 · 41 · 81 · 3 ≡ 43 (mod 100).
The number of times you have to square the base is at most then number of binary digits of the exponent, which is proportional to the number of decimal digits. Thus this method can handle exponents which have hundreds of digits. This fact is important for cryptography: it is much easier to exponentiate than it is to do the reverse (extract a root).
3.5 Exercises due February 16 For 1–4, if it’s true, prove it, and if it’s false, give a counterexample.
1. True or False: If a ≡ b (mod m) and c ≡ d (mod n) then ac ≡ bd (mod mn).
2. True or False: If a ≡ b (mod m) and c ≡ d (mod m) then ac ≡ bd (mod m).
3. True or False: the only solutions to x2 ≡ 1 (mod n) are x ≡ ±1.
4. True or False: if b ≡ c (mod m), then ab ≡ ac (mod m).
21 5. The multiplicative inverse of a (mod m) is an integer b such that ab ≡ 1 (mod m). Prove that the multiplicative inverse, if it exists, is unique modulo m.
6. Solve 15x ≡ 4 (mod 79).
7. Solve the system of congruences:
z ≡ 1 (mod 50) z ≡ −1 (mod 71)
8. Compute 3301 (mod 501).
9. Let n ≥ 0 be an integer, and let m = 2n + 1. Show that 22n ≡ 1 (mod m).
10. Let (a, b, c) be a Pythagorean triple. Show that 60|abc.
4 Units modulo m: Fermat’s theorem and Euler’s theorem
4.1 Units For integers a, b and m, we say that b is a (multiplicative) inverse to a modulo m if ab ≡ 1 (mod m). Of course the relation is mutual: if b is an inverse to a, then a is an inverse to b. You have already seen that an inverse is unique if it exists.
Theorem 4.1.1. a has a multiplicative inverse modulo m if and only if gcd(a, m) = 1.
Proof. This is just a special case of a prior theorem: ax ≡ 1 (mod m) has a solution if and only if gcd(a, m)|1, which is to say gcd(a, m) = 1.
The most important thing about units is that they can be canceled from both sides of a congruence. That is, if a is a unit modulo m, and ax ≡ ay (mod m), then we can multiply both sides be the inverse of a to get x ≡ y (mod m).
Theorem 4.1.2. The set of units modulo m is closed under multiplication.
Proof. If a and b have inverses c and d, then ab is also a unit, since (ab)(cd) = (ac)(bd) ≡ 1 (mod m).
22 × Let Um be the set of units modulo m. (This set is also written (Z/mZ) .) The above theorem means we can creat multiplication tables modulo m, like this one for m = 10: 1 3 7 9 1 1 3 7 9 3 3 9 1 7 7 7 1 9 3 9 9 7 3 1 Observe that every row and every column contains every unit exactly once. (Sometimes I call this the “sudoku property”.) This reflects the fact that if a is a unit mod m, then the linear equiation ax ≡ b (mod m) has a unique solution modulo m. Notice also that the table is symmetric about its diagonal: this reflects the fact that ab = ba (multiplication is commutative). In abstract algebra we call this sort of structure an abelian group. Easy and important exercise: Construct a table like this for m = 5, m = 7 and m = 12. Take note of any patterns you observe.
4.2 Powers modulo m Let a be an integer considered modulo m, and consider the sequence of powers a, a2, a3 (mod m), ··· For instance, here are the powers of 2 modulo m for three values of m: m 21 22 23 24 25 26 27 28 29 15 2 4 8 1 2 4 8 1 2 4 16 2 4 8 0 0 0 0 0 0 0 17 2 4 8 16 15 13 9 1 2 4 The first thing we can prove about this is that since there are only finitely many residues modulo m, and infinitely many possible powers, that we can find N > n with aN ≡ an (mod m). But then, multiplying by a gives an+k+1 ≡ an+1 as well, and so on; we infer that the sequence an, an+1, . . . , aN−1 (mod m) is the same as the sequence aN , aN+1, . . . , a2N−n−1. In conclusion, the sequence powers of a modulo m must eventually enter a repeating cycle. A special case occurs when a is a unit modulo m. Then we can cancel the excess powers in aN ≡ an to get aN−n ≡ 1 (mod m). Thus at some point in the sequence of powers, 1 appears.
23 Definition 4.2.1. Let a be a unit modulo m. The order of a modulo m, n written ordm(a), is the smallest power n such that a ≡ 1 (mod m).
Looking at the table above, ord15(2) = 4 and ord17(2) = 8. We’ll resume the study of this ord function a bit later.
4.3 Fermat’s theorem
When p is a prime number, Up is the set of all nonzero residues 1, 2, . . . , p−1. Consider the following table listing an modulo 7: n 1n 2n 3n 4n 5n 6n 1 1 2 3 4 5 6 2 1 4 2 2 4 1 3 1 1 6 1 6 6 4 1 2 4 4 2 1 5 1 4 5 2 3 6 6 1 1 1 1 1 1 Strikingly, row 6 has only 1s. Theorem 4.3.1 (Fermat’s (little) theorem). Let p be a prime number, and let a be a unit modulo p. Then ap−1 ≡ 1 (mod p). Somtimes the theorem is stated a slightly different way: ap ≡ a (mod p) for all integers a (not just units). The only non-unit modulo p is 0, and of course 0p ≡ 0, so the two forms are equivalent. We’ll give two proofs of Fermat’s theorem.
#1. This proof is based on the sudoku property of the multiplication table modulo p. For a unit a, the ath row of the table reads a, 2a, 3a, . . . , (p − 1)a (mod p). But by the sudoku property, this list of residues is just a reordering of 1, 2, 3,..., (p − 1). This means the product of these two lists is the same: a · 2a · 3a ··· (p − 1)a ≡ 1 · 2 · 3 ··· (p − 1) (mod p) The residues 1, 2, 3,..., (p − 1) are all units, so we can cancel them; what’s left over is ap−1 ≡ 1 (mod p).
24 #2. We’re going to prove ap ≡ a (mod p) for all a = 1, 2,... by induction3. The base case 1p ≡ 1 (mod p) is trivial. Now, assuming np ≡ n, we use the binomial theorem: p p p (n + 1)p = np + np−1 + np−2 + ··· n + 1. 1 2 1
The binomial coefficients are p p! = ∈ Z k k!(p − k)!
If k = 1, . . . , p − 1, then neither k! nor (p − k)! is divisible by p (by Theorem p 2.2.2!), but p does divide p! = k!(p − k)!, so (Theorem 2.2.2 again!) k p p| . Therefore (n + 1)p ≡ np + 1 (mod p), so that by the inductive k hypothesis (n + 1)p ≡ n + 1. We win by induction.
4.4 The φ function Definition 4.4.1. For an integer m, φ(m) is the number of units modulo m. In order words, it is the number of integers among 1, 2, . . . , m which are relatively prime with m. This function is sometimes called Euler’s totient function.
The first few values of φ(m) are
3The principal of mathematical induction is a way of proving a proposition P (n) for all n = 1, 2,... . It says that if P (1) is true, and if the implication P (n) =⇒ P (n + 1) is true for any n ≥ 1, then P (n) is true for all n. But we don’t need to assume this as an axiom; it follows from the well-ordering principle! Indeed, if there were some n for which P (n) were false, then by hypothesis n 6= 1. Also P (n − 1) could not be true, since it implies P (n). Again by hypothesis, n − 1 6= 1. Continuing, we find a sequence of positive integers which descends indefinitely, contradiction.
25 m φ(m) 1 1 2 1 3 2 4 2 5 4 6 5 7 6 8 4 9 6 10 4 The first thing I notice is that φ(m) appears to be even for m ≥ 3. (This follows from the fact that the units come in pairs a and −a.) But of course we might want a formula for φ(m). One easy special case is that when p is a prime number, φ(p) = p − 1, since the units are exactly 1, 2, . . . , p − 1. Another case is a prime power pn: among the numbers 1, 2, . . . , pn, the only non-units modulo pn are those numbers divisible by p, so that φ(pn) = pn − pn−1. Theorem 4.4.2. For m and n relatively prime, φ(mn) = φ(m)φ(n). Proof. (This is just a sketch.) We apply the Chinese remainder theorem. Each unit a modulo mn can be reduced modulo m and then modulo n, to create a function Umn → Um × Un. The Chinese remainder theorem shows that this function is one-to-one and onto, so that φ(mn) = φ(m)φ(n).
By combining together what we know so far about φ, we get the following formula.
a1 ar Theorem 4.4.3. If p1 ··· pr is the prime factorization of n, then Y φ(n) = (pai − pai−1). i Note that this requires knowing the prime factorization of n. As far as we know there is no shortcut to finding φ(n) without knowing the prime factorization. Therefore if n has hundreds of digits, φ(n) is very difficult to compute.
4.5 Euler’s theorem Fermat’s theorem has an extension to general moduli m. In fact we can just adapt proof #1 of Fermat’s theorem to obtain Euler’s theorem:
26 Theorem 4.5.1. Let a be a unit modulo m. Then aφ(m) = 1 (mod m).
4.6 Exercises due February 23 1. Compute 23506 (mod 101).
2. Compute 23111 (mod 47).
3. Compute φ(75000).
4. Compute 51000 (mod 18).
5. Prove that if p is prime, and x2 ≡ 1 (mod p), then x ≡ ±1 (mod p).
6. Prove that if p is an odd prime, and a is a unit mod p, then a(p−1)/2 ≡ ±1 (mod p).
7. How many solutions are there to x2 ≡ 1 (mod n), where n is a product of r distinct primes?
8. Prove Wilson’s theorem: If p is prime, then (p − 1)! ≡ −1 (mod p). Strategy: each a = 1, . . . , p−1 has a multiplicative inverse b, and then a and b are distinct unless a = ±1.
9. Fermat’s theorem suggests the following test for primality: if a is a unit mod m, and am−1 6≡ 1 (mod m), then m cannot be prime. Compute 2118 (mod 119), and use this method to show that 119 is composite.
10. Unfortunately, this method is not foolproof. The number 561 is com- posite: 561 = 3 · 11 · 17. Nevertheless, show that for all units a modulo 561, a560 ≡ 1 (mod 561).
5 Orders and primitive elements
5.1 Basic properties of the function ordm Let a be a unit modulo m. Recall that aordm(a) ≡ 1 (mod m), and an 6≡ 1 (mod m) for any integer 1 ≤ n < ordm(a). Thus if we do find a positive n integer n with a ≡ 1 (mod m), we can conclude that ordm(a) ≤ n. In fact a little more is true:
n Theorem 5.1.1. Suppose that a ≡ 1 (mod m). Then ordm(a)|n.
27 Proof. By the division algorithm, we can write n = q ordm(a) + r, where 0 ≤ r < ordm(a). Then
1 ≡ an ≡ (aordm(a))qar ≡ 1qar ≡ ar (mod m).
If r 6= 0, we get a contradiction, since r < ordm(a). Thus r = 0 and n = q ordm(a). Here’s an important corollary. By Euler’s theorem, aφ(m) ≡ 1 (mod m), and therefore ordm(a)|φ(m). (5.1.1)
This is a strong restriction on what ordm(a) could possibly be. It means that if we are interested in finding ordm(a), we don’t need to compute all the powers a, a2,... modulo m, stopping when we reach 1. Instead, we can n compute a for all divisors n of φ(m). The order ordm(a) is the least divisor n for which an ≡ 1 (mod m).
n Theorem 5.1.2. For an integer n, ordm(a ) = ordm(a)/ gcd(n, ordm(a)). Proof. We have
ord (a) n m ord (a) n n (a ) gcd(n,ordm(a)) = (a m ) gcd(n,ordm(a)) ≡ 1 gcd(n,ordm(a)) ≡ 1 (mod m),
n so that ordm(a ) ≤ ordm(a)/ gcd(n, ordm(a)). On the other hand, we have
n n an ordm(a ) = (an)ordm(a ) ≡ 1 (mod m).
n Therefore by the previous theorem ordm(a)|n ordm(a ), so that
ordm(a) n n · ordm(a ). gcd(n, ordm(a)) gcd(n, ordm(a))
n By Lemma 2.2.1, ordm(a)/ gcd(n, ordm(a))| ordm(a ).
5.2 Primitive roots
We have seen that ordm(a)|φ(m) for every unit a modulo m. Sometimes it happens that ordm(a) = φ(m). This happens for instance with 3 modulo 7. The powers of 3 modulo 7 are 1, 3, 2, 6, 4, 5, 1,... . Notice that all units modulo 7 appear in this sequence.
Definition 5.2.1. A unit a is a primitive root modulo m if ordm(a) = φ(m).
28 To determine whether a is a primitive root, you can calculate aφ(m)/p (mod m) for every prime p which divides φ(m). If none of these residues is 1, then a is a primitive root. Here is a chart of the first few positive integers m and their primitive roots.
m prim. roots mod m 1 1 2 1 3 2 4 3 5 2,3 6 5 7 3,5 8 none 9 2,5 10 3,7 11 2,6,7,8 12 none
Later we’ll tackle the question of which m have primitive roots. It turns out that a primitive root exists whenever m is prime. The following theorem explains the term “primitive root”.
Theorem 5.2.2. Let a be a primitive root modulo m. Then for every unit u modulo m, there exists n ∈ Z such that u ≡ an (mod m). Furthermore, n is unique modulo φ(m).
Thus, every unit can be generated from a primitive root.
Proof. We claim that the residues
1, a, a2, . . . , aφ(m)−1 are all distinct modulo m. Indeed if two of them were the same, say ai ≡ aj (mod m) for 0 ≤ i < j < φ(m), then aj−i ≡ 1 (mod m), which is a contradiction because 0 < j − i < φ(m). Also, all of these powers are units. But this list contains φ(m) elements, and that is exactly how many units there are. So the list must contain every unit exactly once. For uniqueness: if an ≡ an0 ≡ (mod m), then an0−n ≡ 1 (mod m), 0 0 so that by Theorem 5.1.1 ordm(a) = φ(m)|n − n, meaning that n ≡ n (mod φ(m)).
29 Theorem 5.2.3. Suppose a is a primitive root modulo m. Then the full set of primitive roots modulo m is n a 1 ≤ n ≤ φ(m), gcd(n, φ(m)) = 1 .
Thus the number of primitive roots modulo m is φ(φ(m)).
Proof. By Theorem 5.2.2, it suffices to say when an is a primitive root. By n n Theorem 5.1.2, ordm(a ) = φ(m)/ gcd(n, φ(m)). Thus a is a primitive root if and only if gcd(n, φ(m)) = 1.
5.3 The discrete logarithm Let m be an integer, and let b be a primitive root modulo m. By Theorem 5.2.2, every unit a is a power of b:
a ≡ bk (mod m).
Here the integer k may be considered modulo φ(m). We set
k = logb(a), and call this the discrete logarithm of a to the base b. For instance, 2 is a 4 primitive root modulo 11, and 2 ≡ 5 (mod 11), so log2(5) = 4. (You have to deduce from context that we are referring to the discrete logarithm here, and not the usual one.) The discrete logarithm obeys some of the usual rules that logarithms do, only modulo φ(m):
logb(xy) ≡ logb(x) + logb(y) (mod φ(m)) n logb(x ) ≡ n logb(x) (mod φ(m)) Unlike the case of usual logarithms, discrete logarithms are not easy to com- pute. If m has hundreds of digits, one knows that there exists a k that makes bk ≡ a (mod m) true, but finding this k is not at all straightforward. There are algorithms to do so, but none that we know so far runs in polynomial time. Thus, the discrete logarithm is hard to compute.
5.4 Existence of primitive roots for a prime modulus Here we will address the question of the existence of primitive roots modulo a prime. The proof is a little involved, so we’ll demonstrate the main idea with an example. Suppose we want to show that there exists a primitive
30 root modulo 59. This means finding a unit of order 58. By (5.1.1), the possible orders of units all divide 58, so they must be 1, 2, 29 or 58. The only element of order 1 is 1, and the only element of order 2 is −1. (This is proved in your exercises from last week – it’s here we use the fact that 59 is prime.) But there are more than 2 units! Therefore there exists an element of order 29 or 58. If there’s an element of order 58, great; that’s a primitive root. Otherwise, suppose x is an element of order 29. What is the order of −x? It must be 29 or 58, since x 6≡ ±1 (mod 59). But (−x)29 = −x29 ≡ −1 (mod 59), so that −x must be a primitive root. In order for the above proof to work, it was important to know that x2 ≡ 1 (mod 59) could have only two solutions, namely ±1. This is a special case of the following theorem:
n n−1 Theorem 5.4.1. Let f(x) = x + an−1x + ··· + a0 be a polynomial with integer coefficients, and let p be a prime. Then f(x) ≡ 0 (mod p) can have no more than n distinct solutions modulo p.
Proof. The proof will follow from the following fact which is familiar from algebra: If f(r) ≡ 0 (mod p), then we can write
f(x) ≡ (x − r)g(x) (mod p) for some polynomial g(x), whose degree is n − 1. (This is a congruence between polynomials – it means that corresponding coefficients on either side are congruent.) This is easy to see when r = 0, because if f(0) ≡ 0 (mod p) it means that c0 ≡ 0 (mod p), so that f(x) (mod p) is divisible by x. In general, we can substitute: f(x+r) has 0 as a root, so f(x+r) ≡ xh(x), and so (substituting back) f(x) ≡ (x − r)h(x − r). Now suppose f(x) has n distinct roots r1, ··· , rn modulo p. Then f(x) ≡ (x − r1)f2(x). Plugging in x = r2, we get 0 ≡ f(r2) ≡ (r2 − r1)f2(r2). But since r2 6≡ r1, we can use Corollary 2.2.2 to get f2(r2) ≡ 0 (mod p). Thus (x − r2) can be factored out of f2(x): f(x) ≡ (x − r1)(x − r2)f3(x). Continuing, we get
f(x) ≡ (x − r1) ··· (x − rn) (mod p).
(There can be nothing left over, because both sides are degree n with unit leading coefficients.) Again by Corollary 2.2.2, there cannot be a root of this other than r1, . . . , rn.
Lemma 5.4.2. Suppose m and n are relatively prime. If ordp(x) = m and ordp(y) = n, then ordp(xy) = mn.
31 mn m n n m Proof. Let d = ordp(xy). On the one hand, (xy) = (x ) (y ) ≡ 1 (mod p), so that d|mn. On the other hand, 1 ≡ (xy)md ≡ ymd, so that by Theorem 5.1.1, n|md, and so (Lemma 2.2.1) n|d. Similarly m|d, and so (since m and n are coprime) mn|d.
Now we return to the problem of finding a primitive root modulo a prime n1 nt p. Suppose φ(p) = p − 1 factors as `1 ··· `t . That is, val`i (p − 1) = ni for i = 1, . . . , t. We first claim that for each i there exists a unit u with (p−1)/`i val`i ordp(u) = ni. Assume otherwise: this would mean that u ≡ 1 (mod p). But this contradicts Lemma 5.4.1, because it would mean that the polynomial x(p−1)/`i − 1 has p − 1 roots modulo p.
Therefore there exists, for each i, a unit ui with val`i ordp(ui) = ni. ni ordp(ui)/`i ni Let vi = ui ; then by Lemma 5.1.2 we have ordp(vi) = `i . Let n1 nt v = v1 ··· vt. By Lemma 5.4.2, ordp(v) = `1 ··· `t = p − 1, so that v is a primitive root. We have proved: Theorem 5.4.3. Let p be a prime. There exists a primitive root modulo p. Note that the above proof is not constructive! That is, it doesn’t give us an algorithm to find a primitive root modulo p. If p is large, we don’t have a great way of finding a primitive root. I will say however that if we happen to know all the prime factors of p − 1, then we can quickly check if a given unit u is primitive (by testing u(p−1)/` 6≡ 1 for all prime ` dividing p − 1), so one might simply test units 2, 3, ··· until one finds a primitive root.
5.5 Exercises due March 2 These exercises constitute your midterm. You may refer to the notes, but not to any outside sources, and you must work on your own4.
1. Find integers x, y, z such that
55x + 35y + 77z = 1.
Please show your method.
2. Let n be an integer. Show that n13 − n is divisible by 2730.
3. True or false: for units a and b modulo m, ordm(ab) = ordm(a) ordm(b). (If true, prove it, if false, give a counterexample.)
4Added Monday Feb. 26: I shouldn’t have to say this, but there are some very real consequences for handing in work that is not your own on an exam. I won’t hesitate to report plagiarism or copying to the Dean.
32 4. True or false: If a is a unit modulo m, and ar ≡ as ≡ 1 (mod m), then agcd(r,s) ≡ 1 (mod m). (If true, prove it, if false, give a counterexam- ple.)
5. True or false: if p is a prime, and a3 ≡ 1 (mod p), then a ≡ 1 (mod p). (If true, prove it, if false, give a counterexample.)
6. Find all primitive roots modulo 17.
7. The decimal expansion of 1/7 is .142857. It repeats with period 6. Find all other integers n such that 1/n has period 6. (You may assume that n is coprime with 10.)
16 8. The number p = 2 + 1 is prime. Find ordp(2). 9. Suppose p is a prime, such that p ≡ 1 (mod 4). Let b be a primitive root modulo p, and let x = b(p−1)/4. Show that x2 ≡ −1 (mod p).
10. Suppose p is a prime, such that p ≡ 3 (mod 4). Show that x2 ≡ −1 (mod p) has no solutions. (Hint: Raise both sides to the power of (p − 1)/2.)
6 Some cryptographic applications
6.1 The basic problem of cryptography Cryptography is the art of sending messages securely. Cryptographers speak of fictional characters Alice, Bob and Eve. Alice and Bob are far apart, and Alice wants to send Bob a private message. (For instance, Alice could be a customer sending her credit card information to Bob’s online store.) If she sends the message directly (via snail mail, courier, wire or e-mail: the medium doesn’t matter!), then Eve the eavesdropper could intercept it, which would be a disaster. So Alice should encrypt her message in some way and send the coded message, so that Eve would not be able to understand it. But then how is Bob supposed to understand it? It almost sounds logically impossible for this to work, but in fact it can be done using some basic number theory.
6.2 Ciphers, keys, and one-time pads Since we’re going to use mathematics, it makes sense to agree upon a way to turn the message into a number. This can be accomplished with a simple
33 substitution (01 for A, 02 for B, etc.), or something more sophisticated (like ASCII). We are going to assume that this substitution is known to all parties (Alice, Bob, and also Eve). Thus Alice wants to send a large number M (perhaps in the hundreds of digits) to Bob. A natural way to do this is a simple substitution cipher: 0 can be replaced with 5, 1 with 3, 4 with 7, etc. (Or perhaps the cipher can be a little more complicated, with a rule for pairs or triples of digits.) Perhaps Alice and Bob have met earlier to agree on which cipher to use. But such a cipher is relatively easy for Eve to crack: the regularities of language make it easy to guess which letter corresponds to which sequences of numbers. (Indeed, sometimes there are puzzles in the newspaper which ask to solve such a cipher.) Another idea is to use a key K. This is a random number with approx- imately the same size as M, which is known to Alice and Bob and no one else. To send a secure message, Alice can send C = M + K to Bob, who can then compute C − K = M. This has the advantage of being virtually unbreakable: since K is random, Eve has no way of guessing it and breaking the code. But it has some major disadvantages too: Alice and Bob would have had to meet in advance to agree on the key K (this is impractical if Alice is a customer at Bob’s online store!), and they both need to keep K secure as they travel. Not only that, but the key should only be used once: if Alice wants to send another message M 0, she sends C0 = M 0 + K. Then Eve, who has intercepted both C and C0, can compute C − C0 = M − M 0, the difference between the two messages–too risky. This last problem can be overcome if Alice and Bob share a one-time pad: a whole collection of keys K1,K2,... , all random and unrelated to one another, so that Alice can send Bob as many messages as there are keys. But this still has the problem that Alice and Bob need to agree on these keys in a secure location, which is often impractical.
6.3 Diffie-Hellman key exchange Remarkably, there is a way for Alice and Bob to agree on a key K with- out ever meeting, in such away that Eve cannot determine K even if she intercepts all communications. As a warm-up, here’s a riddle: Suppose Alice is sending a suitcase to Bob containing sensitive material. Both Alice and Bob own padlocks that can lock the suitcase, but the padlocks have different keys. How can Alice securely send Bob the suitcase? Here’s the solution: Alice locks the suitcase with her lock and sends it
34 to Bob. Bob receives it and places his own padlock on it, and sends it back to Alice with both locks. Alice then removes her own lock and sends it a third time to Bob, who removes his own padlock and opens the suitcase. In Diffie-Hellman key exchange, the idea of the riddle is combined with number theory. Alice chooses a large prime p, at least in the hundreds of digits and certainly larger than her message M. By Theorem 5.4.3, there exists a primitive root g modulo p. Alice finds one and makes both g and p public. (There is the good question of how quickly one can find a primitive root; we won’t be so concerned with this. If the factorization of p − 1 is known, it is easy to check that a particular unit is a primitive root; so one can guess and check until a primitive root is found.) Alice and Bob both choose secret numbers a and b, respectively. These should be very large but still less than p. They should also be relatively prime to p−1. Alice calculates A = ga (mod p), and B computes gb (mod p) (remember that modular exponentiation runs in polynomial time, so this is reasonable for them to do). The next steps are: 1. Alice sends A to Bob. 2. Bob sends B to Alice. 3. Alice computes Ba (mod p). 4. Bob computes Ab (mod p). In fact Alice and Bob have computed the same quantity, since Ba ≡ (gb)a ≡ (ga)b ≡ Ab (mod p). Call this common value K. Then K is the key that Alice and Bob can use to encode messages between each other. The whole process is called Diffie-Hellman key exchange. Why is it secure? Let’s say Eve wants to spy on Alice and Bob. She knows the prime p and its primitive root g, because these are public. She intercepts A and B. Can she use them to compute K in a reasonable amount of time? It is believed that the answer is no. The Diffie-Hellman problem is: Given ga and gb modulo p, compute gab modulo p. This is what Eve has to solve to get the private key K. Note the relationship with the problem of computing discrete logarithms. If Eve has a magical discrete-log calculator, ab she can compute a = logg A and b = logg B and then easily get g (mod p). But as far as we know there is no rapid way to compute discrete logarithms, and also no way to solve the Diffie-Hellman problem without them.
35 6.4 RSA The RSA algorithm is another number-theory based encryption method. It allows Alice to directly encrypt her message to Bob. Its security is based on the difficulty of factoring large integers. Bob is the intended recipient of secure messages. He chooses two large primes p and q, and computes N = pq. Bob publishes N but keeps its factorization secret. Bob has access to φ(N) = (p − 1)(q − 1). We remark that knowledge of φ(N) is equivalent to knowledge of p and q. Indeed, if you know φ(N) = N − (p + q) + 1, then you know p + q and pq = N, from which you can solve for p and q. Bob also chooses a private decryption key d. The number d can be small, but it should not be 1. It should also be relatively prime to φ(N). Secretly, Bob computes the inverse of d modulo φ(N). That is, he finds an integer e such that de ≡ 1 (mod φ(N)). This is the public encryption key. Bob publishes e. Alice would like to use RSA to send a secure message to Bob. Her message takes the form of an integer M which is less than N. (If her message is longer than N, she can break it up into smaller chunks. Also, if her message is particularly short, she should use a simple “padding” process to make sure that M is almost as large as N.) Since the encryption key e is public, Alice can use it to compute C = M e (mod N). This is the encrypted message. Alice sends it to Bob. To decrypt the message, Bob computes Cd (mod m). This works because
Cd ≡ (M e)d ≡ M ed ≡ M (mod N).
Why is the last congruence true? If M is relatively prime to N, it fol- lows from Euler’s theorem: Since ed ≡ 1 (mod φ(N)), we have M ed ≡ M (mod N). (It’s still true even in the unlikely event that M is divisible by p or q–you should figure this out for yourself.) Now suppose Eve overhears everything. She knows N, e and C = M e (mod N). To figure out M, she needs to extract an eth root of C modulo N. This is known as the RSA problem. If Eve can factor N, she can compute φ(N) and then use Euclid’s algorithm to compute d (the inverse of e modulo φ(N)), and then compute M the same way that Bob did. It is believed that solving the RSA problem is very difficult. But there is no proof that it can’t be done efficiently. For all we know, a criminal mastermind has already solved the problem and therefore can break RSA- based cryptosystems. The only evidence to the contrary is that very smart people have tried and failed to solve the RSA problem.
36 7 Quadratic Residues
7.1 Which numbers are squares? Which numbers are perfect squares? In other words, given n, when does √ n make sense? The answer depends very much on what sort of number system we are working with:
• In the real numbers R, the squares are the nonnegative numbers.
• In the complex numbers C, every number is a square.
• In the integers Z, it is easy to decide whether n is a square. If n < 0 it is certainly not. If n > 0, we can use a calculator to compute the √ real number n; if anything appears past the decimal point, n is not a square. Thus, deciding whether n is a perfect square is a polynomial- time algorithm.
• In the rational numbers Q, a positive reduced fraction p/q is a square if and only if both p and q are.
Much less obvious is the question of perfect squares in Z/mZ. That is, given an integer a, we could like to know if there is a solution to
x2 ≡ a (mod m).
(This is the natural progression of things: we have already solved linear congruences modulo m, and now we are moving on to degree 2 equations.) If a solution exists, we call a a quadratic residue modulo m; otherwise it is a quadratic nonresidue. (These terms are due to Gauss.) For instance, 10 is a square modulo 13 because 72 ≡ 10 (mod 13). Is 2 a square modulo 13? We can answer the question using a chart like this:
37 x x2 (mod 13) 0 0 1 1 2 4 3 9 4 3 5 12 6 10 7 10 8 12 9 3 10 9 11 4 12 1 Since 2 doesn’t appear on the second column, it is a quadratic nonresidue modulo 13. Note that the second column is palindromic (ignoring the initial zero), because (−x)2 = x2. So to answer the question of whether 2 was a quadratic residue, it was only really necessary to compute the squares of 0, 1,..., 6. This method is horribly inefficient for large values of m. It takes m/2 steps to decide if a is a quadratic residue modulo m this way, which is unacceptable.
7.2 Euler’s criterion If the modulus is a prime number p, there is a far better way to decide if a is a quadratic residue. Theorem 7.2.1 (Euler’s criterion). Let p be an odd prime. Suppose that a is a unit modulo p. Then a is a quadratic residue if and only if
a(p−1)/2 ≡ 1 (mod p).
Proof. If a ≡ x2 (mod p), then
a(p−1)/2 ≡ (x2)(p−1)/2 ≡ xp−1 ≡ 1 (mod p) by Fermat’s theorem. Conversely, suppose a(p−1)/2 ≡ 1 (mod p). By Theorem 5.4.3, there exists a primitive root g modulo p; let us write a ≡ gk (mod p). Then
1 ≡ a(p−1)/2 ≡ gk(p−1)/2 (mod p).
38 Since ordp(g) = p − 1, Theorem 5.1.1 implies that (p − 1)|k(p − 1)/2. Can- celling the integer (p − 1)/2 from both sides gives us 2|k, so that k = 2`. Therefore a ≡ gk ≡ (g`)2 (mod p) is a quadratic residue.
Theorem 7.2.2. Let p be an odd prime. There are exactly (p + 1)/2 quadratic residues modulo p. (Since 0 is obviously a quadratic residue, this is the same as saying that there are exactly (p − 1)/2 quadratic residues which are units.) Proof. We have already observed that the complete list of unit quadratic residues is 12, 22,..., ((p − 1)/2)2 (mod p). We are done if we can show that the members of this list are distinct. Suppose 1 ≤ x, y ≤ (p − 1)/2 and x2 ≡ y2 (mod p). Then p|x2 − y2 = (x − y)(x + y), so that (Lemma 2.2.1) p|(x − y) or p|(x + y), which is to say x ≡ ±y (mod p). Since x, y belong to the range 1,..., (p − 1)/2, x ≡ −y is impossible, so that x ≡ y (mod p).
Euler’s criterion gives a polynomial time algorithm for deciding whether a unit a is a quadratic residue modulo an odd prime p. However, Euler’s criterion does not tell us how to find a solution to x2 ≡ a (mod p). This is a harder problem. The following theorem is another interpretation of the problem in terms of discrete logarithms. Theorem 7.2.3. Let p be an odd prime and let a be a unit modulo p. Let g be a primitive root modulo p. Then a is a quadratic residue modulo p if and only if logg(a) is even. k Proof. Let k = logg(a), so that a ≡ g (mod p). If k is even, then a is obvi- 2 2 ously a quadratic residue. Conversely if a ≡ x , then logg(a) ≡ logg(x ) ≡ 2 logg(x) (mod p − 1). Since p − 1 is even, this implies that logg(a) is even as well.
We remark that the quadratic residues modulo p are 0 together with
1, g2, g4, . . . , gp−3.
A special case is a = −1. When is −1 a quadratic residue modulo p? Informally, we are asking whether the imaginary number i exists modulo p. Theorem 7.2.4. Let p be an odd prime. −1 is a quadratic residue modulo p if and only if p ≡ 1 (mod 4).
39 Proof. This follows right away from Euler’s criterion, since (−1)(p−1)/2 is 1 if and only if p ≡ 1 (mod 4).
7.3 Exercises due March 16 (This is assignment #5.)
1. List the quadratic residues modulo 13.
2. How many quadratic residues are there modulo 9, 25, 27? Formulate a conjecture about the number of squares modulo pn, where p is an odd prime and n ≥ 1.
3. The number p = 28 + 1 is prime. Decide if 2 is a quadratic residue modulo p. Do the same for p = 216 + 1.
4. Let m = p1 ··· pn be a product of distinct odd primes pi. How many units modulo m are squares?
5. (2 pts) Let m = p1 ··· pn be a product of distinct odd primes pi. Under what conditions does x2 ≡ −1 (mod m) have a solution? How many solutions are there?
6. (2 pts) Let p be an odd prime, and let a be an integer. Prove that there exists a solution to x2 + y2 ≡ a (mod p).
7. (2 pts.) Let p be an odd prime, and let x = [(p − 1)/2]!. Prove that
x2 ≡ (−1)(p+1)/2 (mod p).
(You will need Wilson’s theorem, (p − 1)! ≡ −1 (mod p).) This gives another proof that if p ≡ 1 (mod 4), then x2 ≡ −1 (mod p) has a solution.
8 Quadratic Reciprocity
8.1 The Legendre symbol In the real numbers R, the nonzero squares are exactly the positive numbers, and the nonsquares are exactly the negative numbers. From this we deduce that the product of two nonsquares is a square. This is not at all true in Z, since for instance 2 ··· 3 = 6 is not a square. But this property is recovered in Z/pZ for an odd prime p:
40 Theorem 8.1.1. Let p be an odd prime. Then in Z/pZ:
1. The product of two nonzero quadratic residues is again a nonzero quadratic residue.
2. The product of a nonzero residue and a nonresidue is a nonresidue.
3. The product of two nonresidues is a residue.
Proof. Suppose x and y are two units modulo p. Let g be a primitive root modulo p. Then logg(xy) ≡ logg(x)+logg(y) (mod p−1). By Theorem 7.2.3, a unit is a residue if and only if its logg is even. Therefore the theorem is reduced to the observation that even plus even is even, even plus odd is odd, and odd plus odd is even.
Definition 8.1.2. Let p be an odd prime, and let a be an integer. The Legendre symbol is defined as 1, a is a unit residue modulo p a = −1, a is a nonresidue modulo p p 0, p|a.
(Often this symbol is pronounced “a on p”.) Theorem 8.1.1 can now be restated elegantly as follows: for integers a and b, ab a b = . p p p Furthermore, by Euler’s criterion we have a a(p−1)/2 ≡ (mod p). p
8.2 Some reciprocity laws Let us look for some patterns in the Legendre symbol. The patterns will a take this form: we would like to predict what p is, based on what p is modulo some other number. Such a rule is called a reciprocity law. The simplest case is when a = −1, where we have Theorem 7.2.4. This says that ( −1 1, p ≡ 1 (mod 4) = (−1)(p−1)/2 = p −1, p ≡ −1 (mod 4).
41 The next case to examine is a = 2. It turns out that that the correct reciprocity law is ( 2 2 1, p ≡ ±1 (mod 8) = (−1)(p −1)/8 = p −1, p ≡ ±3 (mod 8). We will not prove this law in its entirety right now; instead we will offer the following partial result.
2 Theorem 8.2.1. If p ≡ 1 (mod 8), then p = 1. Our proof will be based on the following observation about complex numbers (!). Let z = e2πi/8. This is a primitive 8th root of 1, because z8 = 2πi k iθ e = 1, but z 6= 1√ for 1 ≤ k < 8. Using Euler’s√ formula e = cos θ+√i sin θ, we find z = (1 + i)/ 2 and z−1 = (1 − i)/ 2. Therefore z + z−1 = 2.
Proof. Let g be a primitive root modulo p. Since p ≡ 1 (mod 8), we may (p−1)/8 4 set z = g ; by Theorem 5.1.2, ordp(z) = 8 and ordp(z ) = 2; the latter relation tells us that z4 ≡ −1 and therefore z2 ≡ −z−2 (mod p). Let α = z + z−1. Then α2 = (z + z−1)2 = z2 + z−2 + 2 ≡ 2 (mod p). Therefore 2 is a quadratic residue modulo p.
The same reasoning can be used to prove the following reciprocity law:
−3 Theorem 8.2.2. If p ≡ 1 (mod 3), then p = 1. √ For this, one is inspired by the equation ω + ω−1 = −3, where ω = e2πi/3. The reader is invited to check the details.
8.3 The main quadratic reciprocity law Theorem 8.3.1. Let p and q be distinct odd positive primes. Then
p q p−1 q−1 = (−1) 2 2 q p The symmetry between p and q is the reason Theorem 8.3.1 is called a reciprocity law. The right side of the equation is −1 if p ≡ q ≡ 3 (mod 4), and 1 in all other cases. Thus a restatement of Theorem 8.3.1 is the following:
p q q = p , p ≡ 1 (mod 4) or q ≡ 1 (mod 4), p q q = − p , p ≡ q ≡ 3 (mod 4).
42 5 p As an example, since 5 ≡ 1 (mod 4), Theorem 8.3.1 predicts that p = 5 5 for all positive odd primes p 6= 5. We confirm this for p = 11: 11 = 1 2 11 1 (since 5 ≡ 4 (mod 11)), and indeed 5 = 5 = 1. Theorem 8.3.1 is a truly deep result. It was first proved by Gauss around 1797. Gauss (and others) would go on to publish many proofs. Later on in this course, we will present on of Gauss’ proofs. Theorem 8.3.1 provides a strategy for computing the Legendre symbol. 91 For instance, let’s compute 101 . The first step is to factor the “numerator”: 91 = 7 · 13. Therefore 91 7 13 = 101 101 101 101 101 = 7 13 3 10 = 7 13 3 2 5 = 7 13 13 3 5 = − 7 13 7 13 = 3 5 1 3 = 3 5 5 2 = = = −1. 3 3
Notice the steps involved: factor the numerator(s), apply quadratic reci- procity, reduce the numerator(s) modulo the denominator(s), and then re- peat. If a and p are very large, then this method is actually impractical, because of the factoring step.
43 8.4 The Jacobi symbol 91 In the example of 101 above, suppose we didn’t know that 91 was com- posite. We would then proceed to apply quadratic reciprocity directly:
91 101 = 101 91 10 = 91 2 5 = 91 91 5 = − 91 91 1 = − = − = −1. 5 5
We arrived at the correct answer regardless! In fact we can justify the above manipulations using an extension of the Legendre symbol which allows composite (but odd) numbers in the denomi- nator. For a positive odd number P which is the product of primes p1 ··· pt, we define the Jacobi symbol
t a Y a = . P p i=1 i Then the Jacobi symbol is multiplicative in both its numerator and denom- a b inator. Another important observation is that P = P whenever a ≡ b (mod P ). It turns out that the Jacobi symbol obeys much the same reciprocity laws as the Legendre symbol.
Theorem 8.4.1. Let P be a positive odd number. The Jacobi symbol has the following properties: