Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580...

67
Math 480/580 Number Theory Notes Richard Blecksmith

Transcript of Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580...

Page 1: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

Math 480/580 Number Theory Notes

Richard Blecksmith

Page 2: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420
Page 3: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

Contents

Chapter 1. Introduction 51. Beginning Exercises 52. Counting the primes 6

Chapter 2. Math 420 Number Theory Review 91. Divisors 92. Divisibility 93. Congruences 104. Congruence Facts 115. Induction 126. The Division Algorithm 137. Mod n Tables 158. The Pails of Water Problem 159. Greatest Common Divisor 17

Chapter 3. Continued Fractions 191. Finite Continued Fractions 192. Infinite Continued Fractions 233. Quadratic Irrationals - a Detailed Example 254. Quadratic Irrationals - The General Situation 285. Lagrange’s Theorem 336. Continued Fraction Worksheet 367. Three Important Theorems 38

Chapter 4. Diophantine Questions 411. Perfect Numbers 412. Fermat’s Method of Descent 433. Sums of Squares 46

Chapter 5. Congruences and Polynomials 491. Linear Congruences ax ≡ b mod m 502. Euler’s Phi Function 513. Polynomial Congruences 54

3

Page 4: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4 CONTENTS

4. Primitive Roots 56

Chapter 6. Quadratic Residues 611. The Legendre Symbol 612. Euler’s Criterion 623. Gauss’s Lemma 634. Quadratic Reciprocity 65

Page 5: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 1

Introduction

1. Beginning Exercises

#1. [Adding Fractions] When is the sum of two fractions ab+ c

d(written in lowest

terms) an integer?

#2. [Factoring in your head] Factor 999919 in your head.

#3. [Perfect numbers] A numper n is called perfect if it is the sum of all of its divisorsexcept n itself. For example, n = 6 is perfect, since 6 = 1 + 2 + 3. What are thenext two perfect numbers? Can you write these two numbers as sums of consecutivecubes?

#4. [Composites] Show that for any n > 1, n4 + 4 is always a composite number.

#5. [How many apples?] Mary has a bag full of apples. When they are counted threeat a time, there is eactly one left over. When they are counted five at a time, thereare three left over. How may apples does Mary have?

#6. [Reducing fractions] Write the fraction5439519

8651166in lowest terms.

#7. [Find the remainder] What is the remainder when 1581000000 is divided by 7?

#8. [How many primes] How many numbers whose decimal expansion have the form101010 · · · 101 (beginning and ending with 1 and alternating between 0 and 1) areprime?

5

Page 6: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

6 1. INTRODUCTION

2. Counting the primes

Never underestimate the value of a theorem which counts something– John Olson

(i) Let S = {p1, p2, p3, . . . , pj} be a collection of (distinct) primes.Let x be a positive real number.Let f(x) = the number of integers n, 1 ≤ n ≤ x, such that p does not divide n if p isa prime not in set S, in other words, f(x) counts only those integers between 1 andx whose prime factors all lie in set S.

(ii) Lemma. f(x) ≤ 2j√x.

Proof:n = pe11 pe22 · · · pejj (ei ≥ 0)

= m2pǫ11 pǫ22 · · · pǫjj (ǫi = 0 or 1)

There are at most√x choices of m and 2j choices of ǫ1, ǫ2, . . . , ǫj .

So f(x) ≤ 2j√x. �

(iii) Let π(x) = the number of primes in the interval 1 to x.

Fix x a positive intger and let p1, p2, . . . , pj be the primes in order: 2, 3, 5, 7, 11, . . . ,pj which are less than or equal to x.Let S = {p1, p2, p3, . . . , pj}.π(x) = j

f(x) = xBy the lemma, f(x) = x ≤ 2j

√x = 2π(x)

√x

Hence,√x ≤ 2π(x)

Taking logs, 12log x ≤ π(x) log 2.

So, π(x) ≥ log x2 log 2

.

(iv) One consequence is another proof that there are infinitely many primes,since π(x) tends to infinity as x → ∞.

(v) Start with π(x) ≥ log x2 log 2

.

Let x = pn (the n-th prime)π(x) = n

n ≥ log pn2 log 2

log pn ≤ 2n log 2So pn ≤ 22n.

Page 7: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. COUNTING THE PRIMES 7

(vi) Theorem.∞∑

n=1

1

pn= ∞.

Proof: Assume not.Let j be large enough so that

∞∑

n=j+1

1

pn<

1

2, that is,

1

pj+1

+1

pj+2

+ · · · < 1

2

Let S = {p1, p2, p3, . . . , pj}f(x) ≤ 2j

√x, for any positive integer x

x−f(x) = the number of integers between 1 and x which are divisible by some primept, t > j.The number of integers n, 1 ≤ n ≤ x, which are divsible by p is ≤ x

p.

That is, at most xpt

integers between 1 and x are divisible by pt.

x− f(x) ≤ x

pj+1

+x

pj+2

+x

pj+3

+ · · ·

= x( 1

pj+1

+1

pj+2

+1

pj+3

+ · · ·)

x− f(x) ≤ x12

12x ≤ f(x)

12x ≤ 2j

√x√

x ≤ 2j+1

which is impossible, since x was arbitrary and j is fixed. �

(vii) Since∞∑

n=1

c

n1+ǫ< ∞, ǫ > 0,

it is false that 1pn

≤ cn1+ǫ for all n ≥ N .

Therefore, pn ≤ 1cn1+ǫ for all infinitely many n.

(viii) It is known that pn ∼ n log n.

Page 8: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420
Page 9: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 2

Math 420 Number Theory Review

1. Divisors

We begin with the definitions of two important sets in number thoery.

Definition 2.1. The set of naturanl numbers is N = {1, 2, 3, 4, 5, . . . }. N isalso called the set of positive integers.

Definition 2.2. The set of integers is Z = {. . . ,−3,−2,−1, 0, 1, 2, 3, 4, . . . }.

Question. Why do we use the letter “Z” for the set of integers, instead of “I”? Hint:Sprechen Sie Deutsch?

2. Divisibility

Definition 2.3. Given integers a and b. We say that a divides b if and only ifthere exists an integer q such that aq = b. Equivalently we say a is a divisor of b orthat b is a multiple of a.

Notation: Write a | b for a divides b and a ∤ b for a does not divides b.

Example: 2 | 12, 3 ∤ 20.

Here are some important facts about divisors:

Theorem 9. Let a, b, and c be integers.(i) If a | b and b | c, then a | c(ii) If a | b, then a | bc.(iii) If a | b and a | c, then a | b+ c.(iv) If a | b and a | c, then a | b− c.

Based on your experience in Math 420, you should be able to prove the abovetheorem using the formal definition of divides.

9

Page 10: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

10 2. MATH 420 NUMBER THEORY REVIEW

Theorem #10. Let a and b 6= 0 be integers. If a | b, then a ≤ |b|.

Comment: This last theorem states the obvious fact that a bigger number cannotpossibly divide a smaller number (other than 0). For example, we do not need tocheck that 101 does not divide 17; it’s too big to be a divisor. Just because thetheorem is obvious does not mean that writing a correct proof is easy, as this problemdemonstrates. Think of writing the proof as “developing a firm grasp of the obvious.”

Question #11. What can you say about a | b if

(a) b = 0?(b) a = 0?(c) a = 1?

3. Congruences

Definition 2.4. Given a positive integer n. We say that two integers a and b arecongruent mod n, written

a ≡ b (mod n)

if and only if n | a− b.

Note that the previous definition of “divides” is essential in making the definitionof “congruent – (mod n).”

For example, 1234 ≡ 10 (mod 9) because 1234 − 10 = 1224 = 9 × 136 and13 ≡ −11 (mod 12) because 12 | 13− (−11) = 24.

Question 12. Answer each of the following:

(a) Is 45 ≡ 9 (mod 4) ?(b) Is 37 ≡ 2 (mod 5) ?(c) Is 37 ≡ 3 (mod 5) ?(d) Is 37 ≡ −3 (mod 5) ?

Question 13. Find the smallest non-negative integer r such that

(a) (11 + 23− 5) ≡ r (mod 7)(b) 1000 ≡ r (mod 7)(c) −250 ≡ r (mod 33)

Exercise 14. Characterize all integers n which satisfy the following congurences:

Page 11: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. CONGRUENCE FACTS 11

(a) n ≡ 0 (mod 2)(b) n ≡ 1 (mod 2)

Exercise 15. Characterize all integers n which satisfy the following congurences:

(a) n ≡ 0 (mod 3)(b) n ≡ 1 (mod 3)(c) n ≡ 2 (mod 3)(d) n ≡ 4 (mod 3)

4. Congruence Facts

Congruences (≡) act like equals (=). The relevant theorems fall into two separatecategories: (1) basic properties and (2) arithemtical properties.

The three basic properties of = are: (i) anything is equal to iteself; (ii) you canswitch sides: a = b implies b = a; and (iii) you can connect a string of equations:a = b and b = c implies a = c. It turns out that congruence works in exactly thesame way:

Theorem #16. Let a, b, c and n > 0 be integers. Then(i) a ≡ a (mod n)(ii) a ≡ b (mod n) implies b ≡ a (mod n)(iii) a ≡ b (mod n) and b ≡ c (mod n) implies a ≡ c (mod n).

This theorem shows that congruence mod n is an equivalence relation, that is, arelation which is (i) reflexive, (ii) symmetric, and (iii) transitive.

The basic arithmetic properties of = are: “you can add, subtract, or multiplyequals to get equals,” that is, if a = b and c = d, then a + c = b + d, a − c = b − d,and a× c = b× d. Analogous statements hold for congruences as well:

Theorem #17. Let a, b, c, d and n > 0 be integers. If a ≡ b (mod n) and c ≡ d(mod n), then(i) a+ c ≡ b+ d (mod n)(ii) a− c ≡ b− d (mod n)(iii) a× c ≡ b× d (mod n).

Division, as we will see later, requires more thought.

Page 12: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

12 2. MATH 420 NUMBER THEORY REVIEW

5. Induction

Principle of Induction. Let P (n) be a statement about the positive integer n. Inorder to show that P (n) is true for all positive integers n, it suffices to show that(i) First Case: P (1) is true;(ii) Next Case: If P (n) is true for the integer n, then statement P is true for the nextinteger n+ 1.

Example: Find the sum of consecutive odd numbers. Let’s experiment:

1 = 1

1 + 3 = 4

1 + 3 + 5 = 9

1 + 3 + 5 + 7 = 16

Question: What is the pattern 1, 4, 9, 16?Answer: They are all squares.Question: Does this pattern continue for the next sum when n = 5?Answer: Let’s check:

1 + 3 + 5 + 7 + 9 = 16 + 9 = 25,

another square.

Conjectured Formula:

1 + 3 + 5 + · · ·+ (2n− 1) = n2

Geometric Proof: For example, when n = 5, we can decompose a 5 square into fiveL-shaped pieces whose areas are 1, 3, 5, 7, and 9.

1 3 5 7 9

Induction Proof:

P (n) : 1 + 3 + 5 + · · ·+ (2n− 1) = n2

Page 13: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

6. THE DIVISION ALGORITHM 13

First Step: P (1) is true: 1 = 1

Next Step: Assume P (n) is true and show that P (n + 1) is also true. The idea is tostart with the formula P (n). Add the next odd number 2(n + 1) − 1 to both sides,and hopefully transform the equation into P (n+ 1), like this:

1 + 3 + 5 + · · ·+ (2n− 1) = n2 [P (n)]

1 + 3 + 5 + · · ·+ (2n− 1) + (2(n+ 1)− 1) = n2 + 2(n+ 1)− 1 [add 2(n+ 1)− 1]

1 + 3 + 5 + · · ·+ (2n− 1) + (2(n+ 1)− 1) = n2 + 2n+ 1 [algebra]

1 + 3 + 5 + · · ·+ (2n− 1) + (2(n+ 1)− 1) = (n+ 1)2 [factoring].

This last equation is precisely P (n+ 1), the next case of the proposition we want toprove. By induction, P (n) is true for all positive integers. �

Exercise #18. Find a formula for the sum

T = 1 + 2 + 3 + · · ·+ n

These numbers are called triangular numbers. Do you see why?

Use induction to prove the following theorem about congruences:

Theorem #19. Let a, b, k, and n > 0 be integers. If a ≡ b (mod n), then ak ≡ bk

(mod n).

One interesting application of this theorem is that when working mod 9, all powersof 10 are congruent to one. That is, 10 ≡ 1 (mod 9) implies 10k ≡ 1k = 1 (mod 9)for all exponents k. Use this fact to prove that the following divisibility test:

Theorem #20. The number n is divisible by 9 if and only if the sum of the base 10digits of n is divisible by 9.

Problem #21. For each divisior d = 2, 3, 4, · · · , 11, 12, devise a test to determinewhether the number n written in decimal as

n = dtdt−1 · · · d3d2d1d0is divisible by d.

6. The Division Algorithm

Theorem. [Division Algorithm] Suppose a > 0 and b are integers. Then there is aunique pair of integers q and r such that

b = aq + r where 0 ≤ r < a.

Page 14: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

14 2. MATH 420 NUMBER THEORY REVIEW

The number q is called the quotient and r is called the remainder.

Example: b = 23 and a = 7. Here 23 = 3×7+2, so q = 3 and r = 2. In grade schoolyou would have said “7 goes into 23 three times with a remainder of two.” When

you learned about fractions (in the fourth grades), you wrote23

7= 3

2

7. Observe also

that the restriction that the remainder r lies in the range 0 ≤ r ≤ a − 1 is essentialfor uniqueness. For example, it is true that 23 = 2× 7 + 9, but we cannot use r = 9as a remainder because it is larger than the divisor 7; given b = 23, a = 7, the onlyvalues of q and r satisfying 23 = 7q + r, 0 ≤ r ≤ 6 are 3 and 2, respectively.

In proving the division algorithm it is convenient to aasume that n is positive andthat the divisor is greater than 1.

Question #23. What are the values of q and r if a = 1?

Exercise #24. Verify the division algorithm for n > 0 and d > 1 by induction onthe variable b. Hint: the idea is simply to show that if the division algorithm holdsfor a positive integer n, then it also holds for n+1. This will require you to considertwo separate cases, based on the size of r.

Exercise #25. Once you know the division algorithm holds for positive integers, howcan you extend the theorem to negative integers?

Exercise#26. Prove the “uniqueness” part of the Division Algorithm. That is, provethat the integers q and r are unique, which means that if (q1, r1) satisfies b = q1a+r1,0 ≤ r1 < a and (q2, r2) also satisfies b = q2a + r2, 0 ≤ r2 < a, then q1 = q2 andr1 = r2.

The next theorem shows a connection between the division algorithm and con-gruences.

Theorem #27. Let a, b, and n > 0 be integers. Then a ≡ b (mod n) if and only ifa and b have the same remainder when divided by n.

Exercise #28. Use congruences to find the following remainders:

(a) when 2009× 1864 + 195 is divided by 7(b) when 2× 3× 4× 5× · · · × 19× 20 is divided by 11(c) when 2100 is divided by 7

Page 15: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

8. THE PAILS OF WATER PROBLEM 15

7. Mod n Tables

Here are the addition and multiplication tables, when the remainders are reducedmodulo 5:

+ 0 1 2 3 4

0 0 1 2 3 41 1 2 3 4 02 2 3 4 0 13 3 4 0 1 24 4 0 1 2 3

× 0 1 2 3 4

0 0 0 0 0 01 0 1 2 3 42 0 2 4 1 33 0 3 1 4 24 0 4 3 2 1

Let’s examine the times table. The zero row and zero column consists of all 0’s.What did we expect? Zero times anything is zero. If we ignore the 0 row and column,the rest of the times table has some interesting properties. Notice, for example, thenumbers 1, 2, 3, and 4 are scrambled when we multiply by 2, 3, or 4. That is, eachof the rows list the numbers 1, 2, 3, 4 in some order. In the second row we get 2, 4,1, 3; in the third row we get 3, 1, 4, 2; in the last row the numbers are backwards 4,3, 2, 1. This scrambing phenomenon is the key idea in constructing the secret codesdiscussed in a future section.

Problem #29. Construct the + and × tables mod 7.

Problem #30. Construct the + and × tables mod 6.

8. The Pails of Water Problem

You have a 5 and a 7 quart pail. How can you measure exactly 1 quart of water,by pouring water back and forth between the two pails? You are allowed to fill andempty each pail as many times as needed. [Try to solve this problem before readingfurther!] After a bit of trial and error, you will discover that one solution—there areothers!—is to fill the 5-quart pail three times and empty into the 7-quart pail twice.This method given can be written more succicntly as:

3× 5− 2× 7 = 1.

The general Pails of Water Problem is: Given integers a and b, find numbers m andn such that

ma+ nb = 1.

Page 16: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

16 2. MATH 420 NUMBER THEORY REVIEW

Let’s say that a is smaller than b. If you can’t think of the solution right away becausethe numbers are too large, reduce the problem to two smaller numbers, by dividingthe smaller number a into b, getting a quotient q and a remainder r. Write this as

r = b− q × a.

Record this equation as you will need it later. The original POW problem a andb reduces to solving POW with the numbers r and a. You can write this reduc-tion as (a, b) → (r, a). If the numbers r and a are still too big, reduce again, bydividing r into a. Eventually you will reach two numbers that you can do in yourhead. Starting with this “easy” solution, carefully work backwards, substituting the“remainder” equations you previously recorded, until you reach a solution using theoriginal numbers a and b.

Example. Solve the Pails of Water Problem (POW) with the numbers 100 and 77.

Solution: First, we divide 77 into 100. Since 77 goes into 100 one time, with remainder23, we write

23 = 100− 77

and record this equation for later use. Now we have reduced the POW problem tothe numbers 77 and 23. But these numbers are still too big; it is not obvious how toget 1 from the numbers 77 and 23. So we reduce again. The smaller number 23 goesinto 77 three times, with remainder 8. Write this as

8 = 77− 3(23).

Can we solve POW with 23 and 8? Yes! 3× 8− 1× 23 = 1. Now we substitute theprevious “remainder” equations to work our way back to the original numbers 100and 77:

1 = 3(8)− 23 solution with 8 and 23

= 3(77− 3(23))− 23 substitute 8 = 77− 3(23)

= 3(77)− 9(23)− 23 expand the first parentheses

= 3(77)− 10(23) gather the 23’s together

= 3(77)− 10(100− 77) substitute 23 = 100− 77

= 3(77)− 10(100) + 10(77) expand the second parentheses

= 13(77)− 10(100) gather the 77’s together.

Page 17: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

9. GREATEST COMMON DIVISOR 17

We can easily check our solution 13 × 77 − 10 × 100 = 1 with a calculator:13× 77 = 1001 and we know (without a calculator) that 10× 100 = 1000.

The method described in this section for solving the pails of water problem is calledthe Euclidean algorithm. This particular procedure dates back over two thousandyears ago to the Greek mathematician Euclid, who also founded plane geometry.

We will develop a more automatic method using continued fractions in the nextsection.

Question 32. You cannot obtain 1 quart of water with 6 and 10 quart pails. Whynot? What is the smallest amount you can obtain?

Question 33. Solve POW in your head: (a) 10 and 19; (b) 7 and 9; (c) 11 and 8

Question #34. Another solution with 5 and 7 is: 3 × 7 − 4 × 5 = 1. Show how toget this solution from the solution 3× 5− 2× 7 = 1. Hint: add and subtract 5× 7.

Question 35. Solve POW with

(a) 31 and 9(b) 54 and 37.(c) 2519 and 377(d) make up your own problem

9. Greatest Common Divisor

Definition 2.5. Suppose d | a and d | b. Then d is called a common divisor ofa and b.

Example: Common divisors of 14 and 18 are ±1, ±2.

Question #36. Does any pair of integers a and b always have at least one commondivisor?

Question #37. If you know that a and b have infinitely many common divisors,what must be true about a and b?

Definition 2.6. If a and b are not both 0, then the largest positive commondivisor g of a and b is called the greatest common divisor of a and b.

Notation: Write d = gcd(a, b) or just g = (a, b).

Page 18: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

18 2. MATH 420 NUMBER THEORY REVIEW

Example: gcd(14, 18) = 2.

Exercise 38. Find the greatest common divisor of

(a) 36 and 22(b) 100 and -30.(c) 15 and 28(d) 0 and 28

Notation: When gcd(a, b) = 1 we say that a and b are relatively prime or that ais relatively prime to b. Another way of saying this is to assert that a and b shareno common factors.

Example. 144 and 35 are relatively prime, while 21 and 35 are not.

Theorem #39. (i) If a 6= 0 and b and q are integers, then the common divisors of aand b are the same as the common divisors of a and b+ qa. (That is, d is a commondivisor of a and b if and only if d is a common divisor of a and b+ qa.) In particular,(a, b) = (a, b+ qa).(ii) If a 6= 0 and b = qa+ r, then (a, b) = (a, r).

Using the previous theorem and succesive applications of the Division Algorithmuntil we reach a remainder of zero provides a method for computing the gcd of a andb.

Exercise 40. Compute (12471, 149751).

Exercise 41. Compute (12345, 67890).

If your method reminds you of the POW problem, you are not having an out-of-body deja-vu experience. The method for find gcd’s and the method for solving POWare essentially the same technique. Both are called the Euclidean Algorithm. (ThePOW method is sometimes called the “extended” Euclidean Algorithm.)

Question 42. Back to the pails of water problem. What do you think is the smallestamount of water you can obtain from pails of size a and b?

Exercise #43. Find integers x and y such that 12345x+ 67890y = (12345, 67890).

Page 19: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 3

Continued Fractions

1. Finite Continued Fractions

Definition. A simple continued fraction has the form

q0 +1

q1 +1

q2 +1

. . . qn−1 +1

qn

Note that the numerators are always 1. The q’s are called the partial quotients ofthe continued fraction.

Notation. We use square brackets

[q0, q1, q2, . . . , qn]

to denote the above continued fraction.

Example. Evaluate

2 +1

3 +1

1 +1

4

In computing the value of the continued fraction above, you must work from rightto left, first simplifying 1 + 1

4= 5

4, next simplifying 3 + 4

5= 19

5, and so on, working

your way to the left. As it turns out, it is easier to evaluate continued fractions byworking from left to right.

19

Page 20: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

20 3. CONTINUED FRACTIONS

Definition. If 0 ≤ k ≤ n, then the kth convergent of the continued fraction[q0, q1, . . . , qn] is the fraction

Ak

Bk

= [q0, q1, . . . , qk],

obtained by truncating the original continued fraction at the kth partial quotient.We always express Ak

Bkin lowest terms

Example. Evaluate the convergents A0

B0, A1

B1, A2

B2, A3

B3of [2, 3, 1, 4].

A faster way is to work from left to right, using the following recursion formulas.

Theorem 3.1. The Recursion Theorem

Starting with the values

{

A−2 = 0

B−2 = 1and

{

A−1 = 1

B−1 = 0, the convergents Ak and Bk

can be computed from the previous two values Ak=1, Ak−2 and Bk=1, Bk−2:

Ak = qkAk−1 + Ak−2

Bk = qkBk−1 + Bk−2.

Example. Use these formulas to evaluate the convergents of [2, 3, 1, 4].

qk 2 3 1 4Ak 0 1 2 7 9 43Bk 1 0 1 3 4 19

Theorem 3.2. The Cross-multiply theorem

For k ≥ −1,

Ak−1Bk − AkBk−1 = (−1)k.

Corollary 3.1. If the q’s are integers, then so are Ak and Bk. Moreover,gcd(Ak, Bk) = 1.

Corollary 3.2.

Ak

Bk

− Ak−1

Bk−1

=1

Bk−1Bk

Problem. Expand43

19as a continued fraction.

What’s the point? The Cross Multiply Theorem shows how to solve the Pails ofWater Problem. Given two numbers a and b

Page 21: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

1. FINITE CONTINUED FRACTIONS 21

Example. Solve POW(43,19). First express43

19as the continued fraction [2, 3, 1, 4].

Now compute the last and next to last convergent:

A2

B2

=9

4and

A3

B3

=43

19.

By the Cross-Multiply Theorem,

A2B3 − A3B2 = (−1)3

or

9× 19− 4× 43 = −1

or

4× 43− 9× 19 = 1.

This equations solves POW(43,19): fill the 43-quart pails 4 times and empty into the19-quart pail 9 times.

Exercises:

#44. Prove the Recursion Theorem.

Hint: [q1, q2, . . . , qk−1, qk] = [q1, q2, . . . , qk−1 +1

qk].

#45. Prove the Cross-multiplication Theorem.

#46. Prove Corollary 3.1.

#47. Prove Corollary 3.2.

#48. Find a solution to the Diophantine equation 417x− 172y = 1.

#49. When you write 159as a continued fraction, and then evaluate the convergents,

what is the final convergent? It’s not 159. Why not? Explain how you could use the

final convergent to determine gcd(15,9).

#50. Use the continued fraction expansion of 1234567890

to find d = gcd(12345, 67890).Find a solution in integers to the equation 12345x+ 67890y = d.

#51. Show thatAk

Bk

− Ak−2

Bk−2

=(−1)kqkBkBk−2

#52. Suppose ab= [q0, q1, q2, . . . , qk] and that all the partial quotients qi are positive.

Show thatAk

Ak−1

= [qk, qk−1, . . . , q2, q1, q0]

Page 22: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

22 3. CONTINUED FRACTIONS

andBk

Bk−1

= [qk, qk−1, . . . , q2, q1].

#53. The Fibonacci sequence {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . } is defined recursivelyby F0 = 0, F1 = 1, and for n ≥ 2, Fn = Fn−1 + Fn−2. What is the continued fractionexpansion of Fn/Fn−1?

The next two exercises pave the way into the next section on infinite continuedfractions.

#54. What number has the infinite continued fraction expansion

1 +1

2 +1

2 +1

2 +1

. . .

#55. What is the continued fraction expansion of π = 3.14159265359 . . . ?

Page 23: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. INFINITE CONTINUED FRACTIONS 23

2. Infinite Continued Fractions

Given a non-terminating simple continued fraction

q0 +1

q1 +1

q2 +1

. . .

We define the value of this continued fraction to be the limit of the convergents

limn→∞

An

Bn

Theorem 3.3 (Alternating Series Test). If the alternating series

∞∑

k=1

(−1)k−1bk = b1 − b2 + b3 − b4 + · · ·

satisfies the conditions(i) bk > 0(ii) bk−1 > bk and(iii) lim

n→∞bk = 0,

then the series converges.

Theorem 3.4. If qi ≥ 1 for i ≥ 1, (integers or not), then the simple continuedfraction [q0, q1, q2, . . . ] converges.

Exercises:

Exercise

#56. Prove Theorem 3.4.

Hint: Use the Cross-Multiplication Theorem to write

An

Bn

= q0 +n∑

k=1

(−1)k−1 1

BkBk−1

.

Use the Alternating Series Test to prove that q0 +∞∑

k=1

(−1)k−1 1

BkBk−1

converges.

#57. Show that the even numbered convergents

{

A2k

B2k

}

form an increasing sequence.

Page 24: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

24 3. CONTINUED FRACTIONS

#58. Show that the odd numbered convergents

{

A2k+1

B2k+1

}

form a decreasing sequence.

#59. Show that for any m and k,

A2k

B2k

<A2m+1

B2m+1

.

#60. Prove that if x is the irrational number whose continued fraction representationis [m,m,m, . . . ], then x = 1

2m+

√m2 + 4.

#61. Prove that if x = [a0, a1, a2, . . . ], where a0 ≥ 1, then 1x= [0, a0, a1, a2, . . . ].

Page 25: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

3. QUADRATIC IRRATIONALS - A DETAILED EXAMPLE 25

3. Quadratic Irrationals - a Detailed Example

Consider the following quadratic irrational:

α =5 +

√17

4.

One can check that α satisfies the quadratic polynomial

(

x− 5 +√17

4

)(

x− 5−√17

4

)

= x2 − 5

2x+

25− 17

16= x2 − 10x+

1

2.

Clearing fractions by multiplying through by 2, we see that α is a root of the poly-nomial

2x2 − 5x+ 1

and indeed the quadratic formula applied to this polynomial yields the original valueof α.

Now suppose we want to find the continued fraction expansion of α = (P0 +√17)/Q0 = (5 +

√17)/4. The first partial quotient is

q0 =

5 +√17

4

= 2

since 4 <√17 < 5. Our first iteration is

α = 2 +

(

5 +√17

4− 2

)

= 2 +

(

5 +√17

4− 2

)

= 2 +−3 +

√17

4= 2 +

1

α1

where α1 =4

−3 +√17

. Rationalizing the denominator, we get

α1 =4√

17− 3

√17 + 3√17 + 3

=4(√17 + 3)

17− 9

=4(√17 + 3)

8

=3 +

√17

2

Page 26: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

26 3. CONTINUED FRACTIONS

Notice that we were lucky in the step where the 4 in the numerator divided into the8 in the denominator, leaving α1 in the form

α1 =P1 +

√17

Q1

=3 +

√17

2.

We repeat this process to get the next partial quotient:

q1 =

3 +√17

2

= 3

and

α1 = 3 +

(

3 +√17

2− 3

)

= 3 +

(√17− 3

2

)

= 3 +1

α2

Computing the value of the reciprocal,

α2 =2√

17− 3

√17 + 3√17 + 3

=2(√17 + 3)

17− 9=

2(√17 + 3)

8

=3 +

√17

4=

P2 +√17

Q2

and, once again, a small miracle happened when the 2 divided into the 8. Our thirdpartial quotient is

q3 =

3 +√17

4

= 1

and

α2 = 1 +

(

3 +√17

4− 1

)

= 1 +

(√17− 1

4

)

= 1 +1

α3

Computing the value of the reciprocal,

α3 =4√

17− 1

√17 + 1√17 + 1

=4(√17 + 1)

17− 1

=4(√17 + 1)

16

=1 +

√17

4

Page 27: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

3. QUADRATIC IRRATIONALS - A DETAILED EXAMPLE 27

Our fifth iteration gives

q4 =

1 +√17

4

= 1

,

α3 = 1 +

(

1 +√17

4− 1

)

= 1 +

(√17− 3

4

)

= 1 +1

α4

But we have seen this baby before: α1 =4√

17− 3. So α4 = α1 and the next three

partial quotients will be 3, 1, and 1, the same as the partial quotients for α1. Let’ssummarize what we found. At each stage, starting with α0 = α, we found that

αk =Pk +

√17

Qk

and that

αk = qk +1

αk+1

.

The values are

k qk Pk Qk

0 5 4 21 3 2 32 3 4 13 1 4 14 3 2 35 3 4 16 1 4 1

Thus the continued fraction expansion of α is

α =5 +

√17

4= [2, 3, 1, 1]

where the line drawn over the sequence 3, 1, 1 indicates that these three quotientskeep repeating.

Page 28: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

28 3. CONTINUED FRACTIONS

4. Quadratic Irrationals - The General Situation

Let us generalize the previous example to quadratic irrationals of the form α =r + s

√d, where r and s are rational numbers. We assume that d is not a perfect

square, otherwise α would not be irrational. As in the example, α is a root of thepolynomial

(x− (r + s√d))(x− (r − s

√d)) = x2 − 2rx+ (r2 − ds2).

We can multiply by the lcm of 2r and r2 − ds2 to obtain a polynomial ax2 + bx + c

which has α for one of its roots. By the quadratic formula, these roots are

−b+√b2 − 4ac

2a

−b−√b2 − 4ac

2a.

We can always assume that α will be the choice with the plus sign. If not, justmultiply all three coefficients a, b, and c by −1 and note that

b+√b2 − 4ac

−2a=

−b−√b2 − 4ac

2a.

Thus α can be written

α =P +

√D

Q

where

P = −b, Q = 2a, D = b2 − 4ac.

It follows immediately that

P 2 −D = 4ac = 2Qc.

Now at each step in computing the continued fraction expansion of α we find that

qk =

Pk +√D

Qk

and

αk = qk +1

αk+1

.

Subtracting the partial quotient gives

αk − qk =Pk +

√D

Qk

− qk =1

αk+1

=1

Pk+1+√D

Qk+1

orPk − qkQk +

√D

Qk

=Qk+1

Pk+1 +√D.

Page 29: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. QUADRATIC IRRATIONALS - THE GENERAL SITUATION 29

Cross multiply to get

(Pk − qkQk +√D)(Pk+1 +

√D) = QkQk+1.

Now FOIL the product on the left:

(Pk − qkQk)Pk+1 −QkQk+1 +D + (Pk − qkQk + Pk+1)√D = 0.

Since D is not a perfect square, we must have

(Pk − qkQk)Pk+1 −QkQk+1 +D = 0

Pk − qkQk + Pk+1 = 0.

The second equation gives us a recursion formula for Pk+1:

Pk+1 = qkQk − Pk

Plugging this expression into the first equation above gives

P 2k+1 +QkQk+1 = D.

Replacing k by k − 1 gives

P 2k +Qk−1Qk = D.

Equating these two expressions on the left gives

P 2k+1 +QkQk+1 = P 2

k +Qk−1Qk.

Plugging in our formula for Pk+1 and rearranging terms, we have

QkQk+1 = P 2k +Qk−1Qk − P 2

k+1

= P 2k +Qk−1Qk − (qkQk − Pk)

2

= P 2k +Qk−1Qk − q2kQ

2k + 2qkQkPk − P 2

k

= Qk−1Qk − q2kQ2k + 2qkQkPk

Now divide through by Qk to obtain

Qk+1 = Qk−1 − q2kQk + 2qkPk

= Qk−1 + qk(Pk − (qkQk − Pk))

= Qk−1 + qk(Pk − Pk+1)

This gives us a recursion for calculating Qk+1:

Qk+1 = Qk−1 + qk(Pk − Pk+1)

Notice that these recursive formulas eliminate the need to rationalize the denomina-tors or to perform any divisions in computing the continued fraction expansions ofthe quadratic irrational α. They also supply an easy induction proof that at the kthstage, Pk and Qk are both integers, provided we can show that Q1 is an integer.

Page 30: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

30 3. CONTINUED FRACTIONS

To see that Q1 is an integer, use the formula

P 2k +Qk−1Qk = D

with k = 1:P 21 +Q0Q1 = D.

Since P1 = q0Q0 − P0, the above equation becomes

Q1 =D − P 2

1

Q0

=D − (q0Q0 − P0)

2

Q0

=D − (q0Q0 − P0)

2

Q0

=D − (q20Q

20 − 2q0P0Q0 + P 2

0 )

Q0

=D − P 2

0

Q0

+ 2q0P0 − q20Q0

= −2c+ q0(P0 − P1),

where c is the constant term of the quadratic polynomial with integer coefficientssatisfied by α.

Summary of our recursion formulas:

Pk+1 = qkQk − Pk(1)

P 2k +Qk−1Qk = D(2)

Qk+1 = Qk−1 + qk(Pk − Pk+1)(3)

Q1 = −2c+ q0(P0 − P1)(4)

Note that for k = 1, formula (2) yields (4) if we define

(5) Q−1 = −2c

Page 31: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. QUADRATIC IRRATIONALS - THE GENERAL SITUATION 31

TI-83 program to compute the continued fraction expansion of

(P + sqrt(D)) / Q

This quadratic irrational must come directly from applying

the quadratic formula to a x^2 + bx + c

PROGRAM: CFRAC

:Prompt A,B,C

:-B->P

:2*A->Q

:B^2-4*A*C->D

:-2*C->G

:Lbl L

:ClrHome

:int((P+sqrt(D))/Q)->A

:Disp P,Q,A

:Pause

:A*Q-P->R

:G+A*(P-R)->S

:Q->G

:R->P

:S->Q

:Goto L

Page 32: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

32 3. CONTINUED FRACTIONS

Exercises:

#62. Given a quadratic irrational α, our method requires us to find a polynomialax2 + bx + c with integer coefficients which α satisfies. Show that we can relaxthese conditions slightly, by allowing the polynomial satisfied by α to have the forma2x2 + bx + c

2, where a and c are integers, and b is an even integer. That is, for such

polynomials, the values of D, Pk, and Qk always turn out to be integers.What are the values of a, b, c for

(a)16−

√3

11

(b) α =3 +

√19

5(c) α =

√7

#63. For each of the following numbers, find their (periodic) continued fractions. (Itwill be useful to use the calculator program CFRAC on the previous page.) What isthe period?

(a)16−

√3

11

(b)1 +

√293

2

(c)3 +

√5

7

(d)1 + 2

√5

3

Page 33: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

5. LAGRANGE’S THEOREM 33

5. Lagrange’s Theorem

Our goal here is to prove a very famous theorem about the periodic continuedfractions.

Theorem 3.5 (Lagrange). The continued fraction expansion of an irrational real

number α eventually begins to repeat if and only if α = P+√D

Q, where D is not a

perfect square and P and Q are integers.

We prove the “if” part of this theorem. Let α be a quadratic irrational which

satisfies a polynomial ax2 + bx+ c with integer coefficents, so that α = P0+√D

Q0, where

P0 = −b, D = b2 − 4ac, and Q0 = 2a. In the last section we saw that

Pk+1 = qkQk − Pk(6)

P 2k +Qk−1Qk = D(7)

Qk+1 = Qk−1 + qk(Pk − Pk+1)(8)

We will need the following lemma, whose proof we postpone.

Lemma 3.1. Eventually Qk is positive, that is, there is an integer k0 such that forall k ≥ k0, Qk > 0.

By equation (2), if k ≥ k0 (from the lemma), then

0 < Qk ≤ QkQk+1 = D − P 2k+1.

0 < Qk < D.

Moreover,

P 2k+1 < D,

so

−√D < Pk <

√D.

It follows that the pair of integers (Pk, Qk) must eventually repeat at some point,since there are only finitely many possiblities. �

In order to prove the lemma we need to “review” some basic facts about quadraticsconjugates. First, the quadratic conjugate of α = r+s

√d, where r and s are rational

numbers and d is not a perfect square is α = r − s√d. Here are some well-known

facts about conjugates which you are asked to prove in the homework:

Fact 1. If α satisfies f(x) = ax2 + bx + c, where a, b, c are integers, then so doesα.

Page 34: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

34 3. CONTINUED FRACTIONS

Fact 2. α + β = α + β.

Fact 3. α · β = α · β.

Fact 4. If α ∈ Q, then α = α.

To prove the lemma, we need to investigate the form of the kth convergent Ak

Bk=

[q0, q1, q2, . . . , qk]. We know that α = [q0, q1, q2, . . . , qk−1, αk]. so the recursion formulasgive

α =Ak−2 + αkAk−1

Bk−2 + αkBk−1

.

We can solve this equation for αk:

α(Bk−2 + αkBk−1) = Ak−2 + αkAk−1

αBk−2 + ααkBk−1 = Ak−2 + αkAk−1

αk(αBk−1 − Ak−1) = Ak−2 − αBk−2

αk =Ak−2 − αBk−2

αBk−1 − Ak−1

Taking the congugate of this equation yields

αk =Ak−2 − αBk−2

αBk−1 − Ak−1

.

This last equation can be rewritten

αk = −Bk−2

Bk−1

α− Ak−2

Bk−2

α− Ak−1

Bk−1

.

We know that the limit

limk→∞

α− Ak−2

Bk−2

α− Ak−1

Bk−1

=α− α

α− α= 1.

Since Bn > 0 for all n, it follows that eventually αk will be negative. More precisley,there is a number k0 so large that if k ≥ k0, then αk < 0. Now αk is positive, startingwith n = 1. So for values of k ≥ k0, we have

0 < αk − αk =2√D

Qk

.

Hence Qk > 0 for k ≥ k0. �

Page 35: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

5. LAGRANGE’S THEOREM 35

Exercises:

#64. Find the value of each of the following periodic continued fractions. Express

your answer in the form P+√D

Q, where P , D, and Q are integers.

(a) [1, 2, 3](b) [1, 1, 2, 3](c) [1, 1, 1, 3, 2](d) [3, , 2, 1](e) [1, 3, 5](f) [1, 2, 1, 3, 4]

#65. Prove Facts 1–4 about quadratic conjugates.

#66. Determine the relationship between the continued fraction expansion of α =P+

√D

Qand its conjugate α = P−

√D

Q.

#67. Express a purely periodic continued fraction β = [b0, b1, . . . , bm] as a quadraticirrational, that is, show β satisfies an equation of the form ax2 + bx + c where a, b,and c are integers.

Hint: Use the fact that β = [b0, b1, . . . , bm + 1/β].

#68. Express a periodic continued fraction α = [a0, a1, . . . , an, b0, b1, . . . , bm] as aquadratic irrational.

Hint: Write α = [a0, a1, . . . , an, β], where β = [b0, b1, . . . , bm] is purely periodic.

Page 36: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

36 3. CONTINUED FRACTIONS

6. Continued Fraction Worksheet

(a) For each number in the table below, fill in the values of the continued fraction of√n.

D CFRAC√D

2

3

5

6

7

8

10

11

12

13

14

D CFRAC√D

15

17

18

19

20

21

22

23

24

26

27

D CFRAC√D

28

29

30

31

32

33

34

35

37

38

39

D CFRAC√D

40

41

42

43

44

45

46

47

48

50

Page 37: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

6. CONTINUED FRACTION WORKSHEET 37

(b) Looking for patterns.

(i) At what index does the repeating part begin?

(ii) Is the period always even; always odd; or sometimes even and sometimes odd?

(iii) Can you predict the value of the last entry in the period?

(iv) Is the denominator Qk ever 1? If so, when?

(v) Does the set of partial quotients in a period have any symmetries?

(c) General Formulas

Do you notice any patterns for the continued fraction expansion of numbers ofthe form

(i) m2 + 1?

(i) m2 − 1?

(i) m2 + 2?

(i) m2 − 2?

(d) Pell’s Equation is the equation

x2 −Dy2 = ±1

where D is not a perfect square.

Compute the convergents for 10 of these continued fractions. For each convergentof Ak

Bkof

√D, compute A2

k −DB2k. What do you notice? Do you spot any solutions

to Pell’s equation?

Page 38: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

38 3. CONTINUED FRACTIONS

7. Three Important Theorems

The next theorem states that the convergents of the continued fraction expansionof an irrational number give the “best possible” rational approximations.

Theorem 3.6 (The Approximation Theorem). Let α be an irrational numberwhose continued fraction expansion is

α = [q0, q1, q2, . . . ].

LetAk

Bk

be the k-th convergent of this continued fraction.

(a) If r and s are integers with s > 0 and |sα− r| < |Bkα− Ak|, then s ≥ Bk+1.

(b) The fractionAk

Bk

is closer to α than any other rational with denominator less than

or equal to Bk.

(c)∣

∣α − r

s

∣<

1

2s2, then

r

smust be a convergent of the continued fraction expansion

of α.

The next two theorems were suggested by the√D worksheet.

Theorem 3.7 (C.F. Expansion of√d). The continued fraction of

√d has the

form[q0, q1, q2, . . . , qm−2, qm−1, 2q0]

where qi = qm−i for 1 ≤ i ≤ m2.

Theorem 3.8 (Solution to Pell’s Equation). Suppose that d is a positive nonsquare

and that m is the period of the continued fraction expansion of√d, where

Ak

Bk

denotes

the k-th convergent.(a) The smallest solution to the Pell equation x2 = dy2 = ±1 is x = Am−1 andy = Bm−1.(b) If m is even, this is a +1 solution and there are no −1 solutions.(c) If m is odd, this is a −1 solution and there are both +1 and −1 solutions.(d) Solutions beyond the first occur at the convergents x = Ak and y = Bk, wherek = 2m− 1, 3m− 1, etc.

Page 39: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

7. THREE IMPORTANT THEOREMS 39

Exercises:

#69. Evaluate the continued fraction expansion of the numbers

(a)e− 1

e+ 1; (b)

e+ 1

e− 1; (c) e itself.

To fifty digits,

e = 2.7182818284590452353602874713526624977572470937000

e− 1

e+ 1= 0.46211715726000975850231848364367254873028928033012

e+ 1

e− 1= 2.1639534137386528487700040102180231170937386021508

Do you see the pattern for these three numbers? Compute the first ten convergentsof each of these continued fraction expansions and show that they satisfy the Approx-imation Theorem.

#70. Prove that if d ≡ 3 (mod 4) and d is not a square, then there is no solution inintegers to x2 − dy2 = −1.

#71. Find (periodic) continued fractions α = [a0, a1, a2, . . . ] and β = [b0, b1, b2, . . . ]and determine the “product” γ = [a0b0, a1b1, a2b2, . . . ] .

Page 40: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420
Page 41: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 4

Diophantine Questions

1. Perfect Numbers

First, some notation. let

σ(n) =∑

d|nd,

the sum of all (positive) divisors of n. Let σ∗ denote the funtion

σ∗(n) =∑

d|nd<n

d,

the sum of all positive divisors less than n. Show that the following facts are true:

Fact 1: σ(n) = σ∗(n) + n

Fact 2: n is perfect if and only if σ(n) = 2n.

Fact 3: If q is odd and a ≥ 1 then

σ(2aq) = (1 + 2 + 4 + 8 + · · ·+ 2a)σ(q) = (2a+1 − 1)σ(q).

Theorem 4.1. Let n be an even perfect number. Then n = 2a(2a+1 − 1), wherea ≥ 1 and 2a+1 − 1 is prime.

Proof. Let 2a be the highest power of 2 which divides n. Since n is even, a ≥ 1.Write

n = 2aq,

where q is odd. Since n is perfect, Facts 1, 2, and 3 give us

2a+1q = 2n = σ(n) = σ(2aq) = (2a+1 − 1)(q + σ∗(q)).

This implies

(9) q = σ∗(q)(2a+1 − 1)

so 2a+1 − 1 divides q. Write

q = (2a+1 − 1)q1.

41

Page 42: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

42 4. DIOPHANTINE QUESTIONS

Equation (9) becomes

(10) q1 = σ∗((2a+1 − 1)q1)

.

Now q1 is a divisor of q and we know q1 < q since a ≥ 1 =⇒ 2a+1 − 1 ≥ 3. If q1 > 1,then both 1 and q1 are counted in the sum σ∗(q) and so equation (10) leads to thecontradiction

q1 ≥ 1 + q1.

The only escape from this contradiction is to have q1 = 1. Thus,

q = 2a+1 − 1

and σ∗(q) = 1, which implies that the only divisor of q less than itself is 1, orequivalently, that q is prime. �

#72. Show that in Theorem 4.1 a + 1 must be prime. Equivalently, show that if mis composite, then 2m − 1 is also composite.

#73. A pair (a, b) of positive integers is called an amicable pair of numbers if andonly if σ∗(a) = b and σ∗(b) = a, where σ∗(n) = the sum of the divisors of n whichare less than n. Show that (220, 284) is an amicable pair. Can you find any otherexamples?

Page 43: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. FERMAT’S METHOD OF DESCENT 43

2. Fermat’s Method of Descent

Pierre de Fermat (1601-1665) is often called the “father of modern number theory.”Considering his importance in many areas of mathematics, he was unusual in twoways: he was an amateur and he published very few of his results. His day job wasroyal councillor at the Parliament of Toulouse. Had he done nothing besides givinglegal advice to the court, he would not be remembered today. Happily, he spent muchof his leisure time—his day job paid well—absorbed by mathematical problems.

One of Fermat’s favorite techniques for proving statements in number theory washis method of infinite descent. We shall illustrate Fermat’s descent method in theproof of the following well known fact.

Theorem 4.2. The square root of 2 is irrational.

Proof. (by Descent) Suppose√2 is, contrary to what you might have learned

in high school, a rational number. Then there are positive integers a and b such thatab=

√2. Multiplying by b and squaring both sides gives

a2 = 2b2.

The method of our proof is to show that no matter how small the positive integers aand b are, we can always find another solution

A2 = 2B2,

where A and B are positive integers and A is smaller than a. Observe that

b2 < 2b2 < 4b2.

We may substitute a2 for 2b2 to get

b2 < a2 < (2b)2.

Since b, a, and 2b are all positive integers, we are justified in taking the square rootof this inequality, to get the following important result:

(*) b < a < 2b.

Take

A = 2b− a and B = a− b.

We wish to show the following four facts:

Fact 1. A > 0. (*) =⇒ 2b > a =⇒ 2b− a > 0 =⇒ A > 0.

Fact 2. B > 0. (*) =⇒ a > b =⇒ a− b > 0 =⇒ B > 0.

Page 44: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

44 4. DIOPHANTINE QUESTIONS

Fact 3. A < a. (*) =⇒ b < a =⇒ 2b < 2a =⇒ 2b− a < a =⇒ A < a.

Fact 4. A2 = 2B2.

Plugging A = 2b− a and B = a− b into A2 − 2B2 gives

A2 − 2B2 = (2b− a)2 − 2(a− b)2

= (4b2 − 4ab+ a2)− 2(a2 − 2ab+ b2)

= 4b2 − 4ab+ a2 − 2a2 + 4ab− 2b2

= 2b2 − a2 = 0.

We did it! Both A and B are positive integers, A2 = 2B2, and A is smaller than a.If we repeat this procedure, this time with (A,B) taking the place of (a, b), then wewill find yet another pair—call it (A2, B2)—where A2 is a positive integer less than A

and satisfying A22 = 2B2

2 . The problem is that we cannot continue to find smaller andsmaller positive integers which are all less than a. Otherwise there would be infinitelymany positive integers less that a which is absurd. The whole mess started from ourinitial assumption that

√2 is a rational number. This assumption must wrong and√

2 must be an irrational number. �

It is interesting to compare this proof with the standard proof usually seen (if notremembered) in high school or standard algebra text books.

Proof. (Standard) Suppose√2 is a rational number a

b. Then

a

b=

√2 =⇒ a2 = 2b2.

Write a and b as a product of the same list of primes, using p1 = 2 as the first primein the list:

a = 2e1pe22 · · · perrb = 2f1pf22 · · · pfrr

where the exponents ei, fi are ≥ 0. Then the equation a2 = 2b2 becomes

22e1p2e22 · · · p2err = 22f1+1p2f22 · · · p2frr .

By the uniqueness of prime factorization, we must have

2e1 = 2f1 + 1,

but this is impossible since 2e1 is even and 2f1 + 1 is odd. �

Page 45: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. FERMAT’S METHOD OF DESCENT 45

#74. Use the descent method to show that√3 is irrational. The idea is to follow the

proof for√2: Assume a2 = 3b2, where a and b are positive integers, and then define

A = 3b− a, B = a− b.

#75. What happens if we try to use the method in Exercise 1 above to show that√4 is irrational?

Page 46: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

46 4. DIOPHANTINE QUESTIONS

3. Sums of Squares

Lemma 4.1. Let p > 2 be a prime and suppose a 6≡ 0 (mod p). Then there aresmall numbers s and t such that

sa ≡ t (mod p),

where 0 < |s| < √p and 0 < |t| < √

p.

Proof. We use a counting argument. Let k = ⌊√p⌋. That is, k is the integersatisfying 1 ≤ k <

√p and k + 1 >

√p.

Consider the (k + 1)2 ordered pairs (α, β) where α = 0, 1, 2, . . . , k and β =0, 1, 2, . . . , k. With each pair (α, β) associate the number

αa+ β.

Since (k + 1)2 > p, there must be two different pairs (α1, β1) 6= (α2, β2) such that

α1a+ β1 ≡ α2a+ β2 (mod p)

=⇒ (α1 − α2)a ≡ β1 + β2 (mod p).

Take s = α1 − α2 and t = β1 − β2. Then

sa ≡ t (mod p)

and the other conditions are satisfied:

|s| = |α1 − α2| ≤ k <√p

|t| = |β1 − β2| ≤ k <√p.

Finally, if one of s, t is zero, then so is the other; but s and t cannot both be zerosince (α1, β1) 6= (α2, β2). �

Theorem 4.3 (Fermat). If p ≡ 1 (mod 4), then p = a2 + b2 is the sum of twosquares.

Proof. Solve

a2 ≡ −1 (mod p)

(using Wilson’s Theorem). Now let s and t satisfy the conditions of the lemma:

(i) sa ≡ t (mod p) and

(ii) 0 < s2 < p, 0 < t2 < p.

Then

s2a2 ≡ −s2 (mod p)

Page 47: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

3. SUMS OF SQUARES 47

or equivalently

t2 + s2 ≡ 0 (mod p).

Note that

0 < s2 + t2 < 2p.

The only multiple of p which lies strictly between 0 and 2p is the number p itself. �

#76. Suppose p is a prime and the congruence

x2 + 2 ≡ 0 (mod p)

has a solution x. (This will happen when p ≡ 3 (mod 8) as we shall see later.) Showthat a2 + 2b2 = p has a solution (a, b).

The next question is to ask whether a given number n can be written as a sum ofsquares. The following formula shows that if n1 and n2 can be written as a sum oftwo squares, then so can the product n1n2:

(a2 + b2)(c2 + d2) = (ac− bd)2 + (ad+ bc)2

If n = m2ℓ (n,m, ℓ are positive integers) and ℓ is not divisible by the square of aprime, then ℓ is called the square-free part of n.

#77. Show that a positive integer n is the sum of two squares if and only if thesquare-free part of n is divisible by no prime of the form 4k + 3.

#78. Write n = 2 · 5 · 32 · 13 as a sum of two squares.

#79. Show that n = 4m(8k + 7), where k and m are nonnegative integers, cannot bewritten as a sum of 3 squares.

Theorem 4.4 (Lagrange). Every positive integer is the sum of 4 squares.

To find the values of a and b, let x0 satisfy x20 ≡ −1 (mod p). Carry out the

Euclidean algorithm on p/x0, producing a sequence of remainders r1, r2, . . . , to thepoint wehre rk is less than

√p. Then

p = r2k + r2k+1

if r1 > 1, otherwise p = x20+1. Note x0 = c(p−1)/4, where c is a quadratic non-residue

mod o. It turns out that you can use c = 2 when p ≡ 5 (mod 8) and c = 3 whenp ≡ 17 (mod 24). The remaining case p ≡ 1 (mod 24) can be handled by quadraticreciprocity (to be discussed later).

Page 48: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

48 4. DIOPHANTINE QUESTIONS

Example. p = 10009. Notice p ≡ 1 (mod 24) is the hard case. By manipulationwe find that c = 11, 13, and 17 are all quadratic non-residues. The power

11(p−1)/4 = 11252 ≡ 469 (mod 1009).

Now

1009 = 2× 469 + 71

469 = 6× 71 + 43

71 = 1× 42 + 28

42 = 1× 28 + 15

1009 = 282 + 152

Page 49: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 5

Congruences and Polynomials

Supposef(x) = a0 + a1x+ a2x

2 + · · ·+ asxs

where the ai’s are integers. Consider the polynomial congruence

(11) f(x) ≡ 0 (mod m).

An integer u is a solution to (11) means f(u) ≡ 0 (mod m).Note that if u0 is a solution to (11), then so is any u, where u ≡ u0 (mod m), becauseu ≡ u0 (mod m) implies f(u) ≡ f(u0) (mod m).

By the number of solutions to congruence (11) we mean the number of solutionsfrom any complete residue system mod m.

By a complete set of solutions to (11) we mean any set u1, u2, . . . , ut of solutionssuch that(i) ui 6≡ uj (mod m) for i 6= j and(ii) every solution to (11) is congruent mod m to one of the ui.

Example 1. x2 + 1 ≡ 0 (mod 5)

2, 3 form a complete set of solutionsThe number of solutions is 2.

Example 2. x2 + 1 ≡ 0 (mod p), where p is prime.

This congruence has a solution if and only if p = 2 or p ≡ 1 (mod 4).If u and v are solutions, then either u ≡ v (mod p) or u ≡ −v (mod p).

49

Page 50: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

50 5. CONGRUENCES AND POLYNOMIALS

1. Linear Congruences ax ≡ b mod m

Theorem 5.1. If (a,m) = 1, then the congruence ax ≡ b mod m has exactly onesolution modulo m.

#80. Prove the above theorem.

#81. Example 3. Solve 3x ≡ 50 (mod 113)

Note that ax ≡ b (mod m) implies ax = b + qm for some integer q. So a commondivisor of a,m also divides b.

Example 4. 5x ≡ 1 (mod 15) is not solvable.

Theorem 5.2. Consider the congruence ax ≡ b (mod m).

1. The congruence has a solution if and only if (a,m) | b.

2. If u0 is any particular solution, then a complete set of solutions is:

u0, u0 +m

g, u0 +

2m

g, . . . , u0 +

(g − 1)m

g

where g = (a,m). Thus there are g solutions.

3. A particular solution u0 can be obtained by solving the congruence

a

gx ≡ b

g

(

modm

g

)

This is possible since(

ag, m

g

)

= 1.

#82. Prove Part (1) of the above theorem.

#83. Prove Part (2) of the above theorem.

#84. Prove Part (3) the above theorem.

#85. Example 5. Solve 42x ≡ 12 (mod 78)

Page 51: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. EULER’S PHI FUNCTION 51

2. Euler’s Phi Function

Some Background and Definitions:

Definition 5.1. A set S = {a1, a2, a3, . . . , an} is called a complete residue systemor c.r.s. mod n if and only if every positive integer b is congruent to exactly oneelement ak in S.

Note that every c.r.s. mod n contains exactly n elements.

Example. Each of the following is a c.r.s. mod 11:{0, 1, 2, . . . , 10}{1, 2, . . . , 10, 11}{−5,−4,−3,−2,−2,−1, 0, 1, 2, 3, 4, 5}{0, 2, 4, 6, . . . , 20}

Definition 5.2. A set S = {a1, a2, a3, . . . , ar} is called a reduced residue systemor r.r.s. mod n if and only if every positive integer b which is relatively prime to n iscongruent to exactly one element ak in S.

Note that every r.r.s. mod n contains exactly φ(n) elements, where φ(n) = thenumber of integers k, 1 ≤ k ≤ n, which are relatively prime to n.

Example. Each of the following is a r.r.s. mod 11:{1, 2, . . . , 10}{1, 2, . . . , 10, 11}{−5,−4,−3,−2,−2,−1, 1, 2, 3, 4, 5}{21, 22, 23, . . . , 210} (as we will see later)

Definition 5.3. A function f : Z+ → C is multiplicative if

f(mn) = f(m)f(n)

whenever (m,n) = 1,

Theorem 5.3. The Chinese Remainder Theorem (2 congruence version) Assumethat m and n are relatively prime. Then the system

(12)x ≡ a (mod m)

x ≡ b (mod n)

has a unique solution mod mn.

Page 52: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

52 5. CONGRUENCES AND POLYNOMIALS

To prove the Chinese Remainder Theorem, first solve the linear equation

mr + ns = 1.

Put u = ns and v = mr and note thatu ≡ 1 (mod m)

u ≡ 0 (mod n)and

v ≡ 0 (mod m)

v ≡ 1 (mod n).

A solution to the system (12) is given by

(13) x = au+ bv.

Theorem 5.4. Euler’s phi function φ is multiplicative.

Proof. The proof is based on a careful examination of equation (13). Our goalis to show that as a runs through a r.r.s. mod m and b runs through a r.r.s. mod n,the values of x = au+ bv run through a r.r.s. mod mn. Equivalently, a r.r.s. mod mn

is given by

S = {au+ bv : a ∈ r.r.s. mod m, b ∈ r.r.s. mod n}.To see this, prove two following two things:

#86. the elements of S are distinct modulo mn.

#87. Every number relatively prime to mn is congruent mod mn to some element inS.

It follows that the number φ(mn) of elements in a r.r.s. mod mn is preciselyφ(m) · φ(n). �

Example. Suppose m = 9 and n = 10. Then a r.r.s. mod 9 is {1, 2, 4, 5, 7, 8} and ar.r.s. mod 10 is {1, 3, 7, 9}. In our proof, we have u = 10 and v = −9, giving us thefollowing table of values for x = au+ bv = 10a− 9b:

10a− 9b (mod 90)

b\a 1 2 4 5 7 8

1 1 11 31 41 61 713 73 83 13 23 43 537 37 47 57 77 7 179 19 29 49 59 79 89

It is straightforward to verify that the entries in this table form a r.r.s. mod 90.

Page 53: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

2. EULER’S PHI FUNCTION 53

Formulas. It is easy to see that for a prime p,

φ(p) = p− 1

and

φ(pe) = pe − pe−1 = pe(

1− 1

p

)

.

Thus, since φ is multiplicative, if we know the prime decomposition n = pe11 pe22 · · · perr ,then it is easy to compute φ(n)

φ(n) = φ(pe11 pe22 · · · perr ) = φ(pe11 )φ(pe22 ) · · ·φ(perr )

= (pe11 )(pe22 ) · · · (pekk )(

1− 1

p1

)(

1− 1

p2

)

· · ·(

1− 1

pr

)

= nr∏

k=1

(

1− 1

pk

)

.

Exercises.

#88. For what values of n is φ(n) odd?

#89. Compute φ(3000).

#90. Characterize the set of positive integers n satifying φ(2n) = φ(n).

#91. Find all solutions n to φ(n) = 24.

#92. Prove there is no solution to φ(n) = 14.

#93. Prove or disprove: for a fixed integer m, the equation φ(n) = m has only afinite number of solutions.

#94. What is the range of the φ function? That is, characterize the integers m forwhich φ(n) = m has a solution.

#95. The Phi Tree is constructed by drawing an arrow downward from k to φ(k) foreach integer k = 1, 2, . . . , n. Draw the Phi Tree for n = 20.

#96. Show that lim infn→∞

φ(n)

n= 0.

#97. Find a simple formula involving n forn∑

k=1

φ(k). [Truth in exercises: just to let

you know, no one has ever done this.]

Page 54: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

54 5. CONGRUENCES AND POLYNOMIALS

3. Polynomial Congruences

Polynomials. Suppose f(x) = anxn + an−1x

n−1 + · · ·+ a1x+ a0 where an 6= 0. If allcoefficients ai are integers, we call f(x) an integral polynomial and write f(x) ∈ Z[x],The degree of f(x) is n. Every polynomial except 0 (the zero polynomial) has degree≥ 0. If f(x) and g(x) are integral polynomials, f(x) 6= 0, g(x) 6= 0, then

deg [f(x)g(x)] = deg f(x) + deg g(x).

an is called the leading coefficient of f(x).f(x) is called monic if an = 1.

Theorem 5.5. If f(x) is a monic integral polynomial and g(x) is any integralpolynomial, then there exist integral polynomials q(x) and r(x) such that

g(x) = q(x)f(x) + r(x),

where either r(x) = 0 or deg r(x) < deg f(x).

Hint for proving this theorem: Simple induction.

Corollary 5.1 (Special case.). If f(x) = x− a, where a is an integer and g(x)is any integral polynomial, then there exist an integral polynomial q(x) and an integerc such that

g(x) = q(x)(x− a) + c.

Theorem 5.6 (Lagrange). Suppose f(x) = anxn + an−1x

n−1 + · · · + a1x + a0 isan integral polynomial of degree n, p is a prime, and not all the coefficients ai aredivisible by p. Then the congruence f(x) ≡ 0 (mod p) has at most n solutions in anyc.r.s. mod p.

#98. Prove Lagrange’s theorem. Hint: see the hint to the previous theorem.

Question: Where do we use the hypothesis that p is prime in this proof?

Theorem 1 (Wilson’s Theorem). If p is a prime,

(p− 1)! ≡ −1 (mod p).

#99. Prove Lagrange’s theorem. Use Lagrange’s Theorem to get a second proof ofWilson’s Theorem as follows: Consider the polynomial

f(x) = (x− 1)(x− 2)(x− 3) · · · (x− (p− 2))(x− (p− 1))− (xp−1 − 1).

Page 55: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

3. POLYNOMIAL CONGRUENCES 55

Show this polynomial has degree p−2. Now use Fermat’s little Theorem to show thatf(x) has p − 1 roots mod p: 1, 2, 3, . . . , p − 1. What does Lagrange’s Theorem tellyou about every coefficient of f(x)? Now consider the constant coefficient of f(x).

Page 56: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

56 5. CONGRUENCES AND POLYNOMIALS

4. Primitive Roots

Order of a number. If (a, n) = 1 then we know by Euler’s generalization of Fermat’slittle theorem that

aφ(n) ≡ 1 (mod m).

We call be the smallest positive integer h such that

ah ≡ 1 (mod m)

the order of a modulo n and we write

h = ordn(a).

Remarks. 1. Note that h is defined only if (a,m) = 1.2. a−1 ≡ ah−1 (mod n).3. ordn(1) = 1; ordn(n− 1) = 2 for n > 2.

Theorem 5.7. Assume (a, n) = 1 and let h = ordn(a). Then(i) i ≡ j (mod h) if and only if ai ≡ aj (mod n).(ii) ak ≡ 1 (mod n) if and only if h|k.(iii) h|φ(n).(iv) No two of the powers a, a2, a3, . . . , ah are congruent modulo n.

#99. Prove Statement (i).

#100. Show that Statements (ii) and (iv) follow from statement (i).

#101. Prove Statement (iii).

Statement (iii)

Proposition 5.1. If ordn(a) = h, then

(i) ordn(ak) =

h

(h, k)(ii) ordn(a

k) = h ⇐⇒ (h, k) = 1.

#102. Prove Statement (i).

Statement (ii) clearly follows from (i).

Theorem 5.8. If n is a positive integer, then∑

d|nφ(d) = n,

where the sum is over all the positive divisors of n.

Page 57: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. PRIMITIVE ROOTS 57

Proof. For each positive divisor d of n, let

A(d) = {k : 1 ≤ k ≤ n and (k, n) = d}.

Claim: If f(d) = the number of elements in A(d), then

f(d) = φ(n

d

)

.

Example. n = 12

d 1 2 3 4 6 12

φ(d) 1 1 2 2 2 4

d A(d)

1 {1, 5, 7, 11}2 {2, 10} = 2 {1, 5}3 {3, 9} = 3 {1, 3}4 {4, 8} = 4 {1, 2}6 {6} = 6 {1}12 {12} = 12 {1}

#103. Prove the claim.

#104. Use the claim to prove Theorem 5.8. �

Theorem 5.9. Suppose p is a prime and h|p− 1. Then exactly φ(h) numbers inany r.r.s. modulo p have order h.

Definition 5.4. A number a which has order φ(n) is called a primitive rootmodulo m.

Remark. If g is a primitive root mod n, then g, g2, . . . , gφ(n) is a r.r.s. mod n.

Proof. If h|p − 1, let g(h) count the number of integers in a reduced residuesystem modulo p which have order h. Clearly

(1)∑

h|p−1

g(h) = p− 1.

Page 58: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

58 5. CONGRUENCES AND POLYNOMIALS

We know from a previous theorem that

(2)∑

h|p−1

φ(h) = p− 1.

It suffices to show

(3) g(h) ≤ φ(h) for all h|p− 1.

g(h) = φ(h) follows from (1), (2), and (3).

Proof of (3): Fix a divisor h of p−1. If no integers have order h mod p, fine, g)h) = 0and thus (3) holds in this case. Suppose, on the other hand, there exists an integer asuch that ordp(a) = h. Let

S = {a, a2, . . . , ah}.We know that no two of the powers in S are congruent modulo p. Moreover, eachnumber in S satisfies the congruence

(4) xh ≡ 1 (mod p).

But this congruence has no more than h solutions in any r.r.s. modulo p by Lagrange’sTheorem. Hence every solution to (4) is congruent modulo p to some number in theset S. In particular, every number of order h mod p is congruent to some number inS. We know that ordp(a

k) = h if and only if (h, k) = 1. So exactly φ(h) numbers inS have order h. This proves g(h) = φ(h) and so statement (3) holds in this case. �

As a corollary to the above theorem, we have

Theorem 5.10. There is always a primitive root modulo the prime p; in fact thereare φ(p− 1) primitive roots modulo p in any r.r.s. modulo p.

There are many open questions about the size of the smallest positive primitiveroot mod p.• It is known that there is a primitive root modulo p in the interval 1 ≤ x ≤ 2

√p.

• It is not known whether there is a primitive root modulo p in the interval 1 ≤ x ≤√p.

• It is not known whether 2 is a primitive root for infinitely many primes.

Application. Suppose p is a prime and we want to solve the equation

xk ≡ a (mod p),

where (a, p) = 1.First find a primitive root g modulo p.

Page 59: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. PRIMITIVE ROOTS 59

Write x = gy and a ≡ gb (mod p).The equation becomes

gky ≡ gb (mod p)

or equivalently,ky ≡ b (mod p− 1)

and we know how to solve linear congruences.

Exercise #105. Solve x9 ≡ 5 (mod 71). Use the fact that g = 7 is the smallestpositive primitive root mod 71.

Exercise #106. Solve x5 ≡ 23 (mod 71).

Exercise #107. Use primitive roots to give another proof of Wilson’s Theorem.

#108. Prove the following

Theorem 5.11. Let p be an odd prime and write

p− 1 = qe11 qe22 · · · qerrwhere the qi are prime and ei ≥ 1. Then g is a primitive root mod p if and only if

gp−1

qi 6≡ 1 (mod p)

for every i = 1, 2, . . . , r.

Exercise #109. Show that 14 is a p.r. mod 29.

Page 60: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420
Page 61: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

CHAPTER 6

Quadratic Residues

1. The Legendre Symbol

Solving a general quadratic equation

Solving a quadratic equation boils down to solving binary congruences of degree2 for prime powers, and applying the Chinese Remainder Theorem. Once we have asolution to x2 ≡ a (mod p), we “lift” to a solution for higher powers of p, if possible.So we turn our attention to solving binary congruences of degree 2 modulo a primep.

Definition. Given (a, p) = 1. If there is a solution to

(14) x2 ≡ a (mod p)

then a is called a quadratic residue of p. If there is no solution to (14) then a is calleda quadratic non-residue of p.

Definition. The Legendre symbol(

ab

)

is taken as +1 if x2 ≡ a (mod p) is solvableand (a, p) = 1, −1 if it is not solvable, and 0 if p | a.

One way to determine the quadratic residues mod p is to square the numbersa = 1, 2, 3, . . . , p−1

2. For example, if p = 11, this list is

12 = 1, 22 = 4, 32 = 9, 42 = 16 ≡ 5, 52 = 25 ≡ 3

These squares are the quadratic residues: 1, 3, 4, 5, 9. The non-residues are themissing residues mod 11: 2, 6, 7, 8, 10.

Another way to find the quadratic residues is to first find a primitive root g modp and apply the following

Theorem 6.1. If g is a primitive root mod p, then a is a quadratic residue modp if and only if a ≡ g2k mod p. That is, the quadratic residues are the even powers ofg mod p.

#110. Prove Theorem 6.1.

61

Page 62: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

62 6. QUADRATIC RESIDUES

Since 2 is a primitive root mod 11, the quadratic residues mod 11 are

22 = 4, 24 = 16 ≡ 5, 26 = 64 ≡ 9, 28 = 256 ≡ 3, 210 = 1024 ≡ 1

The same list as before.

For large primes, this method is impractical. It requires p−12

calculations. Oftenwe have a specific number a and we simple wish to know whether a is a quadraticresidue or non-residue mod p.

2. Euler’s Criterion

Theorem 6.2 (Euler’s Criterion for quadratic residues).

(15)

(

a

p

)

≡ ap−1

2 (mod p).

#111. Prove Theorem 6.2.

Theorem 6.3. The Legendre symbol has the properties

(1) If a ≡ b (mod p), then

(

a

p

)

=

(

b

p

)

.

(2)

(

ab

p

)

=

(

a

p

)(

b

p

)

.

(3)

(

a2

p

)

= 1.

#112. Prove Theorem 6.3.

Application. Find

(

3

11

)

. By Euler’s Criterion

(

3

11

)

≡ 35 = 243 ≡ 1 (mod 11).

Application. When a = −1 Euler’s Criterion tells us(−1

p

)

= (−1)p−1

2 .

Page 63: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

3. GAUSS’S LEMMA 63

Since the Legendre symbol satisfies the multiplicative property (2), to evaluate

(

2

p

)

,

first factor a into primes a = q1q2 · · · qr and then evaluate each

(

qip

)

. We therefore

need to determine

(

q

p

)

when q is a prime.

3. Gauss’s Lemma

Instead of the standard reduced residue system where 1 ≤ k ≤ p−1, we sometimesuse the residues centered about 0: −(p− 1)/2, . . . ,−2,−1, 1, 2, 3, . . . , (p− 1)/2.

Theorem 6.4 (Gauss’ Lemma). Let m be the number of elements in the set

1a, 2a, 3s, · · · , p− 1

2a

whose residues lie in the interval(

−p2, 0)

. Then(

a

p

)

= (−1)m.

Proof. Denote the positive residues in the interval(

0, p2

)

by r1, . . . , rℓ and the

negative residues in the interval(

−p2, 0)

by −r′1, . . . ,−r′m.

#113. Show that:

(i) ℓ+m = p−12

(ii) the numbers r1, . . . , rℓ, r′1, . . . , r

′m are 1, 2, . . . , p−1

2in some order.

(iii)

p−1

2∏

k=1

(ka) ≡ ap−1

2

[p− 1

2

]

! ≡ℓ∏

1

ri

m∏

1

(−r′j) ≡ (−1)m[p− 1

2

]

! (mod p).

(iv) ap−1

2 ≡ (−1)m (mod p)

(v) Statement (iv) yields Gauss’ Lemma. �

Application. a = 2

The set in Gauss’ Lemma is

1 · 2, 2 · 2, 3 · 2, . . . , p− 1

22.

Page 64: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

64 6. QUADRATIC RESIDUES

Clearly

k · 2 <p

2if k <

p

4Therefore, the values of ℓ and m in the proof of Gauss’ Lemma are:

ℓ =⌊p

4

and m =p− 1

2−⌊p

4

.

Cases to consider:

p = 8t+ 1 m = 4t− 2t = 2t

p = 8t+ 3 m = 4t+ 1− 2t = 2t+ 1

p = 8t+ 5 m = 4t+ 2− (2t+ 1) = 2t+ 1

p = 8t+ 7 m = 4t+ 3− (2t+ 1) = 2t+ 2.

#114. Show that:

(16)

(

2

p

)

=

{

+1 if p ≡ 1, 7 (mod 8)

−1 if p ≡ 3, 5 (mod 8).

The parity of m matches the parity of1

8(p2 − 1). Therefore,

(

2

p

)

= (−1)1

8(p2−1).

#115. Application. Let Mp = 2p − 1 be a Mersenne number and q = 2p+ 1, whereq is prime and p is prime of the form 4k + 3. Prove that q | Mp.

Example. p = 11 = 4k + 3q = 2 · 11 + 1 = 23 is prime∴ 23 | 211 − 1

Exercise #116. Show that there are infinitely many primes of the form 8k + 7.Hint: consider prime factors of 8x2 − 1.

Page 65: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. QUADRATIC RECIPROCITY 65

4. Quadratic Reciprocity

Theorem 6.5 (Quadratic Reciprocity). Let p and q be distinct odd primes. Then(

p

q

)(

q

p

)

=

{

1 if p ≡ 1 (mod 4) or q ≡ 1 (mod 4)

−1 if p ≡ 3 (mod 4) and q ≡ 3 (mod 4).

Theorem 6.6 (Gauss’ Lemma). Let p be an odd prime and x be relatively primeto p. For each a in the range 1 ≤ a ≤ p−1

2, write xa = pa′ − r, where 1 ≤ r ≤ p− 1.

(Note r 6= 0 since p 6 | x.) Let m count the number of a such that 1 ≤ r ≤ p−12. Then

(

x

p

)

= (−1)m.

Proof. (of the Reciprocity Theorem.) Write p = 2P+1 and q = 2Q+1. Considerall integers a in the range 1 ≤ a ≤ P such that for integers q′, a′, and r, we have

(17) qa = pa′ − r,

where 1 ≤ r ≤ P .

Claim: 1 ≤ a′ ≤ Q.

Clearly a′ ≥ 0 and a′ = 0 is impossible. Moreover,

pa′ = qa+ r ≤ qp− 1

2+

p− 1

2=

(q + 1)(p− 1)

2< p

q + 1

2= p(Q+ 1).

Dividing by p yields a′ < Q+ 1, which implies a′ ≤ Q, as claimed.

Let m = the number of all such a satisfying equation (17). By Gauss’ Lemma,(

q

p

)

= (−1)m.

Now consider all a′ in the range 1 ≤ a′ ≤ Q such that

(18) pa′ = qa− r,

where 1 ≤ r ≤ Q. By the above reasoning, 1 ≤ a ≤ P . If n = the number of a′

satisfying equation (18), then

(

p

q

)

= (−1)n. We wish to show that m+ n is even if

and only if p ≡ 1 (mod 4) or q ≡ 1 (mod 4). The quadratic reciprocity law followsimmediately from this statement.

Define the function R on {1, . . . , P} × {1, . . . , Q} by

R(a, a′) = qa− pa′.

Page 66: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

66 6. QUADRATIC RESIDUES

For m pairs (a, a′) we have 1 ≤ −R(a, a′) ≤ P . For n pairs (a, a′) we have 1 ≤R(a, a′) ≤ Q. Moreover, R(a, a′) 6= 0, since (p, q) = 1. Thus there exist m + n pairs(a, a′) such that

(19) −P ≤ R(a, a′) ≤ Q.

For each pair (a1, a′1) in {1, . . . , P}× {1, . . . , Q} define the “companion” pair (a2, a

′2)

by the conditions

a1 + a2 = P + 1 =p+ 1

2

a′1 + a′2 = Q+ 1 =q + 1

2.

Claim: R(a1, a′1) ∈ [−P,Q] =⇒ R(a2, a

′2) ∈ [−P,Q].

The proof of the claim follows from the following chain of implications:

R(a1, a′1) ∈ [−P,Q]

=⇒ − P ≤ qa1 − pa′1 ≤ Q

=⇒ −Q ≤ pa′1 − qa1 ≤ P

=⇒ −Q+q − p

2≤ pa′1 − qa1 +

q − p

2≤ P +

q − p

2

=⇒ − q − 1

2+

q − p

2≤ q(p+ 1)

2− qa1 −

p(q + 1)

2+ pa′1 ≤

p− 1

2+

q − p

2

=⇒ − p− 1

2≤ q

(

p+ 1

2− a1

)

− p

(

q + 1

2− a′1

)

≤ q − 1

2

=⇒ − P ≤ qa2 − pa′2 ≤ Q

=⇒ R(a2, a′2) ∈ [−P,Q].

Now the companion pair (a2, a′2) differs from (a1, a

′1) unless a1 = a2 and a′1 = a′2.

These equalities happen if and only if 2a1 = P + 1 and 2a′1 = Q+ 1 ⇐⇒ 2a1 =p+12

and 2a′1 = q+12

⇐⇒ p = 4a1 − 1 and q = 4a′1 − 1 ⇐⇒ p ≡ 3 (mod 4) and q ≡ 3(mod 4). Thus, if p ≡ 1 (mod 4) or q ≡ 1 (mod 4), then we see that solutions toinequality (19) come in pairs. Hence m+ n is even and

(

p

q

)(

q

p

)

= (−1)m(−1)n = (−1)even = 1.

Conversely, if p ≡ q ≡ 3 (mod 4), then a1 =p+14, a′1 =

q+14

is its own companion,as noted above. We need to show that in this case, R(a1, a

′1) lies in [−P,Q]. We

Page 67: Math 480/580 Number Theory Notes RichardBlecksmithrichard/Math480/handouts11.pdf · Math 480/580 Number Theory ... Beginning Exercises 5 2. Counting the primes 6 Chapter 2. Math 420

4. QUADRATIC RECIPROCITY 67

calculate

R(a1, a′1) = qa1 − pa′1 = q

(p+ 1

4

)

− p(q + 1

4

)

=q

4− p

4,

and clearly −p2< q

4− p

4< q

2. Hence −P ≤ R(a1, a

′1) ≤ Q. In this case every solution

to inequality (19) has a different companion, except the pair a1 = p+14, a′1 = q+1

4.

Thus, m+ n = the number of solutions to inequality (19) must be odd and(

p

q

)(

q

p

)

= (−1)m(−1)n = (−1)odd = −1. �

Example. p = 17, q = 11. Here P = 8, Q = 5.

Table. R(a, a′) = qa− pa′ = 11a− 17a′.

a\a′ 1 2 3 4 5

1 −6 −23 −40 −57 −74

2 5 −12 −29 −46 −63

3 16 −1 −18 −35 −52

4 27 10 −7 −24 −41

5 38 21 4 −13 −30

6 49 32 15 −2 −19

7 60 43 26 9 −8

8 71 54 37 20 3

Companions for boxed entries where −8 ≤ R(a, a′) ≤ 5:

(1, 1) ↔ (8, 5) (2, 1) ↔ (7, 5) (3, 2) ↔ (6, 4) (4, 3) ↔ (5, 3)

Exercise #117. Work out the R(a, a′) table for primes p = 19, q = 23.

Exercise #118. Determine the solvability of x2 ≡ 37 (mod 89).

Exercise #119. Determine those primes for which x2 ≡ 3 (mod p) is solvable.