number theory - stem2 · 22 hardy’s cab number 42 23 quadratic residues 42 24 diophantine...

57
Number Theory James Emery edit: 5/21/2018 Contents 1 Introduction 3 2 Prime Numbers 3 3 The Prime Number Theorem 4 4 The Euclidean Algorithm for the Greatest Common Divisor 5 5 Python gcd.py Greatest Common Divisor Program 10 6 The Greatest Common Divisor Example in Java 14 7 The Greatest Common Divisor Example in Scheme 17 8 The Greatest Common Divisor Example in Python 17 8.1 Example: Greatest Common Divisor .............. 18 9 Modular Arithmetic 19 10 The Euler Totient Function 23 11 Decimal Expansions 26 12 Fermat’s Theorem 27 13 Fermat’s Little Theorem 28 1

Upload: phungkhanh

Post on 30-May-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Number Theory

James Emery

edit: 5/21/2018

Contents

1 Introduction 3

2 Prime Numbers 3

3 The Prime Number Theorem 4

4 The Euclidean Algorithm for the Greatest Common Divisor 5

5 Python gcd.py Greatest Common Divisor Program 10

6 The Greatest Common Divisor Example in Java 14

7 The Greatest Common Divisor Example in Scheme 17

8 The Greatest Common Divisor Example in Python 178.1 Example: Greatest Common Divisor . . . . . . . . . . . . . . 18

9 Modular Arithmetic 19

10 The Euler Totient Function 23

11 Decimal Expansions 26

12 Fermat’s Theorem 27

13 Fermat’s Little Theorem 28

1

Page 2: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

14 A Fast Exponential Algorithm for Integers 29

15 A Scheme Program to Test For a Number Being Prime 31

16 A Python Program to Test For a Number Being Prime 33

17 Carmichael Numbers 35

18 Fermat’s Last Theorem 36

19 Mersenne Primes 37

20 The Chinese Remainder Theorem 40

21 Wilson’s Theorem 41

22 Hardy’s Cab Number 42

23 Quadratic Residues 42

24 Diophantine Equations 42

25 Goldbach’s Conjecture 43

26 Casting Out Nines 44

27 The Riemann Zeta Function 45

28 The Riemann Hypothesis 46

29 The Sieve of Eratosthenes 46

30 Perfect Numbers 50

31 Twin Primes 50

32 Analytic Number Theory 51

33 Repeating Decimals 51

2

Page 3: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

34 Appendix, Primes Less Than 10000 52

35 Fibonacci Numbers 55

36 Carl Fredich Gauss. The Prince of Mathematicians 55

37 Bibliography 56

38 Index 57

1 Introduction

The Theory of Numbers is that part of mathematics that studies propertiesof the counting numbers and the integers. It has generated many of theconcepts of modern Abstract Algebra.

2 Prime Numbers

A prime number is a positive integer that cannot be written as the productof two integers, each greater than 1. The 25 primes less than 100 are

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.

Any two positive integers n and m, have a greatest common divisor. Thisis written as (m,n). If (m,n) = 1, the numbers are called relatively prime.This means they have no common factor that is greater than 1. Notice thatby the definition every number is relatively prime to 1.The Fundamental Theorem of Arithmetic says that every positive in-teger greater than 1, can be written as a product of powers of primes in aunique way. Thus for example

45 = (2)(32),

and59424750 = (2)(32)(53)(74)(11).

The number 1 is not considered a prime, even though it cannot be writtenas a product of two integers each greater than 1.

3

Page 4: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

There are an infinite number of primes. For suppose there are a finitenumber of them. Multiply these finite numbers together and add 1. Thisnumber is not divisible by any of the finite primes. But a number is eitherdivisible by a prime, or a prime itself. This is a contradiction. Thereforethere are an infinite number of primes. This argument was given by Euclid.

3 The Prime Number Theorem

The prime number theorem says that the number of primes less than naturalnumber n is approximately equal to

n

ln(n).

The Prime Number Theorem. If π(n) is the number of primes less thann, then the ratio of π(n) to n/ ln(n) goes to 1 as n goes to ∞,

limn→∞

(

π(n)ln(n)

n

)

= 1.

The following table suggests that this is true.

n π(n) n/ ln(n) ratio101 4 4.3 0.93102 25 21.7 1.15103 168 144.8 1.16104 1,229 1,086 1.13105 9,592 8,686 1.10106 78,498 72,382 1.08107 664,579 620,420 1.07108 5,761,455 5,428,681 1.06109 50,847,534 48,254,942 1.051010 455,052,511 434,394,482 1.048

A proof can be found in the book on Analytic Number Theory by TomApostle.

4

Page 5: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

4 The Euclidean Algorithm for the Greatest

Common Divisor

Given two positive integers b1 and b2, we shall show how to compute thegcd. Let us assume that b1 > b2. We can divide a larger integer by a smallerone getting a quotient and a remainder. So suppose b1 = 108 and b2 = 30.Dividing 108 by 30 we get a quotient of 3 with a remainder of 18. Theremainder 18 is less than the divisor 30. We can write this as

108 = 3 · 30 + 18,

and . The remainder becomes the next divisor in a continuing sequence:

30 = 1 · 18 + 12.

18 = 1 · 12 + 6

12 = 2 · 6 + 0.

When we get a zero remainder, the previous remainder is the gcd. So gcd= 6. Next we shall prove this algorithm always produces the gcd.

So we start withb1 = k1b2 + b3,

where k1 and b3 are integers. Number k1 is the quotient, b2 is the divisor,and b3 is the remainder. A divisor is always greater than a remainder, sob2 > b3. We may continue this division

b1 = k1b2 + b3,

b2 = k2b3 + b4

b3 = k3b4 + b5

....................

bn−1 = kn−1bn + bn+1

bn = knbn+1 + bn+2,

until the remainder bn+2 is zero, when the division stops. We have a strictlydecreasing sequence of integers

b1 > b2 > b3 > .... > bn+2.

5

Page 6: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Eventually we must reach a step n where the remainder bn+2 is zero, wherewe can’t continue the division. At this point we claim that g = bn+1 is thegreatest common divisor of the integers b1 and b2.

Going backwards, we have

bn = knbn+1,

bn−1 = kn−1bn + bn+1,

bn−2 = kn−2bn−1 + bn,

....................

b1 = k1b2 + b3,

showing that bn+1 eventually divides b2 and b1.Explicitly from the first equation

bn = knbn+1,

we see that bn+1 divides bn. Continuing down the list of equations, we seethat for each k, bk+1 divides bk, and thus ultimately bn+1 divides b2 and b1.So g = bn+1 is a common divisor of b2 and b1. Next we must prove that it isthe largest common divisor.

So suppose h is any other common divisor. That is suppose that h dividesb1 and b2. Then from the first equation of the first list above, namely

b1 = k1b2 + b3,

h must divide b3, and so from the second equation it must divide b4, and soon, down the list, and so h must ultimately divide bn+1. Hence

bn+1 ≥ h.

Therefore g = bn+1 is the gcd of m and n.Note. Our assumption that m = b1 > b2 = n in the calculation is notimportant, because if m=b1 < b2 = n the first step will be

b1 = k1b2 + b3 = 0 · b2 + b3,

that is b3 = b1, so the second step in effect is restarting the calculation,reversing the positions of b1 and b2.

6

Page 7: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

The following proposition is a very important one in number theory andis often used in proofs.

Proposition. Given two integers, b1 ≥ 2 and b2 ≥ 2, there exists twointegers α1 and β1 such that the greatest common divisor g is given by

g = α1b1 + β1b2.

Proof. The Euclidean algorithm presented above for the gcd(b1,b2) = g is

b1 = k1b2 + b3,

b2 = k2b3 + b4

b3 = k3b4 + b5

....................

bn−2 = kn−2bn−1 + bn

bn−1 = kn−1bn + g

bn = knbn+1.

Solving the next to last equation, equation n− 1, for g we have

g = bn−1 − kn−1bn

We can write this asg = αn−1bn−1 + βn−1bn,

whereαn−1 = 1,

andβn−1 = −kn−1.

Now consider the division step n− 2, where equation n− 2 is

bn−2 = kn−2bn−1 + bn.

Solving for bn, we havebn = bn−2 − kn−2bn−1

7

Page 8: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Substituting for bn ing = αn−1bn−1 + βn−1bn,

we have

g = αn−1bn−1 + βn−1(bn−2 − kn−2bn−1)

= βn−1bn−2 + (αn−1 − βn−1kn−2)bn−1

= αn−2bn−2 + βn−2bn−1,

whereαn−2 = βn−1

andβn−2 = αn−1 − βn−1kn−2

This relationship will be repeated, so that at the pth step we find

g = αpbp + βpbp+1,

whereαp = βp+1

andβp = αp+1 − βp+1kp.

So finallyg = α1b1 + β1b2.

Thus by saving the quotients k1, k2, ...kn−1 we can construct the numbers α1

and β1.

Corollary. If integers m and n are relatively prime, then m mod(n) has amultiplicative inverse mod(n).Proof. We have integers α and β so that

1 = αm+ βn,

So that α is the multiplicative inverse of m in the ring Zn, that is

αm = 1 mod(n),

8

Page 9: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

because a multiple of n is zero in the modular ring Zn.

Corollary If p is a prime then the modular ring Zp is a field (Every nonzeroelement has a multiplicative inverse).

There is a java program gcdex.java in the next section for the calculationof the gcd, and the numbers α and β. If the gcd =1, it calculates themultiplicative inverse of m mod n.

We can find α and β by hand. At the beginning of this section wecalculated 6 as the gcd of 108 and 30 as follows:

108 = 3 · 30 + 18,

30 = 1 · 18 + 12,

18 = 1 · 12 + 6,

12 = 2 · 6 + 0.

So from the third line the gcd is

6 = 18− 12

We use the second equation to replace 12 by a combination of 18 and 30,

12 = 30− 18

giving the gcd as6 = 18− (30− 18) = 2 · 18− 30.

Then we use the first line to replace 18 as a combination of 108 and 30

18 = 108− 3(30),

giving the gcd as

6 = 2(108− 3 · 30)− 30 = 2 · 108− 7 · 30.

So α = 2, and β = −7.Corollary If an integer k divides the integers m and n, then k divides theirgreatest common divisor (m,n).Proof. This follows because there exists integers α and β such that

9

Page 10: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

(m,n) = αm+ βn.

Proposition. If r is the remainder on division of a by b, then

(a, b) = (b, r).

Proof. Supposea = kb+ r.

From this (b, r) divides a. Because it also divides b, it thus divides (a, b). Wehave

r = a− kb,

and so because (a, b) divides both a and b, it divides r. Therefore (a, b)divides both b and r, so (a, b) divides (b, r). Obviously two positive integersthat divide each other are equal. It follows that (a, b) = (b, r)

5 Python gcd.py Greatest Common Divisor

Program

This program computes the gcd(m,n) of two integers m and n, and computesnumbers α and β such that

gcd(m,n) = αm+ βn

Running the program:Example 1.

c:\je\py>python gcd.py 510510 27170

m= 510510

n= 27170

510510 = 18 * 27170 + 21450

27170 = 1 * 21450 + 5720

21450 = 3 * 5720 + 4290

5720 = 1 * 4290 + 1430

4290 = 3 * 1430 + 0

10

Page 11: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

v = [gcd,alpha,beta]= [1430, -5, 94]

gcd(m,n)= 1430

alpha*m+beta*n= 1430

So the two numbers have the factor 1430 in common.

1430 = (11)(13)(5)(2),

Example 2.Here is another example showing that the integers 946520984 and 87905179

are relatively prime.

c:\je\py>python gcd.py 946520984 87905179

m= 946520984

n= 87905179

946520984 = 10 * 87905179 + 67469194

87905179 = 1 * 67469194 + 20435985

67469194 = 3 * 20435985 + 6161239

20435985 = 3 * 6161239 + 1952268

6161239 = 3 * 1952268 + 304435

1952268 = 6 * 304435 + 125658

304435 = 2 * 125658 + 53119

125658 = 2 * 53119 + 19420

53119 = 2 * 19420 + 14279

19420 = 1 * 14279 + 5141

14279 = 2 * 5141 + 3997

5141 = 1 * 3997 + 1144

3997 = 3 * 1144 + 565

1144 = 2 * 565 + 14

565 = 40 * 14 + 5

14 = 2 * 5 + 4

5 = 1 * 4 + 1

4 = 4 * 1 + 0

v = [gcd,alpha,beta]= [1, 18825831, -202707557]

gcd(m,n)= 1

alpha*m+beta*n= 1

11

Page 12: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

So these numbers m and n are relatively prime, and α = 18825831 is themultiplicative inverse of m in the ring Zn, because any multiple of n is zeroin the ring Zn.Listing:

#gcd.py greatest common divisor, getting m and n from the command line

# May 30, 2014

#see gcdexample.pi , where m and n are defined inside the program.

import sys

#function greatest common divisor

def gcd(b1,b2):

b=[]

k=[]

rm=[]

v=[]

v=[1,2,3]

b.append(0)

b.append(b1)

b.append(b2)

k.append(0)

rm.append(0)

n=0

while (b2 > 0):

n=n+1

#print " b1= ",b1

#print " b2= ",b2

g=b2

q=b1/b2

k.append(q)

#note, if b2>b1 then q=0, then r=b1 so b1 and b2 are switched

#print " q= ",q

r=b1-b2*q;

b.append(r)

print " ",b1,"=",q,"*",b2,"+",r

rm.append(r)

#print " r= ",r

b1=b2

12

Page 13: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

b2=r

v[0]=g

#print

#print " number of divisions n=",n

#print " b="

#for i in range(1,len(b)):

# print " b[",i,"]=",b[i]

#print " length of k=",len(k)

#print " quotients=",k

#for i in range(1,len(k)):

# print " k[",i,"]=",k[i]

#print " remainders=",rm

#for i in range(1,len(rm)):

# print " rm[",i,"]=",rm[i]

alpha=1

beta=-k[n-1]

#print " g=alpha*b[n-1]+beta*b[n]=",alpha*b[n-1]+beta*b[n]

p=n-2

while (p>0):

tmp=alpha

alpha=beta

beta=tmp-beta*k[p]

#print "p=",p

#print " g=alpha*b[p]+beta*b[p+1]=",alpha*b[p]+beta*b[p+1]

p=p-1

#print

#print " alpha=",alpha," beta=",beta

#print " g=alpha*b[1]+beta*b[2]=",alpha*b[1]+beta*b[2]

v[1]=alpha

v[2]=beta

return v

#function least common multiple

def lcm(m,n):

v=m*n/gcd(m,n)

return v

13

Page 14: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

#main

#print sys.argv

#print sys.argv[0]

na=len(sys.argv)

#print ’number of arguments = ’, na

if( na < 3):

print "gcd.py, greatest common divisor of two integers"

print "Usage: python gcd.py m n "

sys.exit(0)

m=int(sys.argv[1])

print " m= ",m

n=int(sys.argv[2])

print " n= ",n

v=gcd(m,n)

#print " length v = ",len(v)

print " v = [gcd,alpha,beta]=",v

print " gcd(m,n)= ",v[0]

alpha=v[1]

#print " alpha=",alpha

beta=v[2]

#print " beta=",beta

print " alpha*m+beta*n= ",alpha*m+beta*n

6 The Greatest Common Divisor Example in

Java

Here is a java program for the calculation of the gcd, the numbers α and βIf the gcd =1, it calculates the multiplicative inverse of m mod n.

//gcdex.java, greatest common divisor of two integers 1-1-2008

class gcdex{

public static void main(String args[]) {

int b[];

int a[];

int na;

14

Page 15: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

int m;

int n;

int g;

a = new int[2];

b = new int[10];

na=args.length;

if(args.length < 1){

System.out.println(" greatest common divisor of two integers " );

System.out.println(" Usage: java gcd m n " );

return;

}

for(int i=0;i<na;i++){

b[i]=Integer.parseInt(args[i]);

}

m=b[0];

n=b[1];

g=gcd(m,n,a);

System.out.print(" gcd= " + g + "\n");

System.out.print(" a1= " + a[0] + " a2= " + a[1] + "\n");

g=a[0]*m+a[1]*n;

System.out.print(" a1*m+*a2*n= " + g + "\n");

}

//c+ gcd function greatest common devisor of 2 positive integers

public static int gcd(int m,int n, int[] a){

/**

* Input:

* m,n two integers

* Output:

* a two element double array such that

* gcd = a[0]*m + a[1]*n

* Returned Value:

* the greatest common divisor of m and n

* Example program gcdex.java

*/

int k[];

int b1;

int b2;

int b3;

int na;

int nk;

int ns;

int r;

int alpha;

int beta;

int g;

int j;

int tmp;

nk=100;

15

Page 16: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

k = new int[nk];

b1=m;

b2=n;

tmp=b1/b2;

r=b1-tmp*b2;

if(r == 0){

System.out.print(" gcd= " + b2 + "\n");

alpha=0;

beta=1;

g=alpha*b1+beta*b2;

return g;

}

System.out.print(" b1= " + b1 + " b2= " + b2 + "\n");

ns=0;

while(r>0){

k[ns]=b1/b2;

r=b1-k[ns]*b2;

System.out.print(" k[" + ns + "] = " + k[ns] + " r= " + r + "\n");

if(r > 0){

b1=b2;

b2=r;

System.out.print(" b1= " + b1 + " b2= " + b2 + "\n");

ns=ns+1;

}

}

g=b2;

j=ns-1;

alpha=1;

beta=-k[j];

j=j-1;

while(j >= 0){

tmp=alpha;

alpha=beta;

beta=tmp - k[j]*beta;

j=j-1;

}

a[0]=alpha;

a[1]=beta;

return g;

}

}

16

Page 17: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

7 The Greatest Common Divisor Example in

Scheme

Application. To compute the greatest common divisor (a, b),of two inte-gers a and b, we can compute the remainder r of a/b and compute (b, r),recursively. Stopping when the value of b reaches zero.

Here is a Scheme function to do this calculation:

(define (gcd1 a b)

(if (= b 0) a (gcd1 b (remainder a b))))

We have used gcd1 as the name of the function, because there is an actualgcd function built into Scheme.

8 The Greatest Common Divisor Example in

Python

This program computes gcdexample(m,n) where the two integers are de-fined in the program. See also program gcd.py where the integers are definedas command line parameters. The python program computes with long in-tegers.

#gcdexample.py greatest common divisor, m and n defined in program main

#also see command line version gcd.py, getting m and n from command line parameters

import sys

#

#function greatest common divisor

def gcd(m,n):

b1=m

b2=n

while (b2 > 0):

v=b2

q=b1/b2

#note, if b2>b1 then q=0, then r=b1 so b1 and b2 are switched

r=b1-b2*q;

b1=b2

b2=r

return v

#function least common multiple

def lcm(m,n):

v=m*n/gcd(m,n)

return v

17

Page 18: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

#program main

m=2*3*5*7*11*13*14*15*200*189*3574

n=91*93*101*3*7*35789*1000*13*14

print " m=",m

print " n=",n

k=gcd(m,n)

print " gcd(m,n)= ",k

j=lcm(m,n)

print " lcm(m,n)= ",j

mdgcd=m/k

ndgcd=n/k

print " m=m/gcd =",mdgcd

print " n=n/gcd =",ndgcd

d=gcd(mdgcd,ndgcd)

print " gcd(m,n) = ",d

8.1 Example: Greatest Common Divisor

#gcd.py greatest common divisor

import sys

#

#function greatest common divisor

def gcd(m,n):

b1=m

b2=n

while (b2 > 0):

# print " b1= ",b1

# print " b2= ",b2

v=b2

q=b1/b2

# print " q= ",q

r=b1-b2*q;

# print " r= ",r

b1=b2

b2=r

return v

#function least common multiple

def lcm(m,n):

v=m*n/gcd(m,n)

return v

#print sys.argv

#print sys.argv[0]

na=len(sys.argv)

#print ’number of arguments = ’, na

if( na < 3):

print "gcd.py, greatest common divisor of two long integers"

print "Usage: python gcd.py m n "

sys.exit(0)

m=int(sys.argv[1])

18

Page 19: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

#print " m= ",m

n=int(sys.argv[2])

#print " n= ",n

k=gcd(m,n)

print " gcd= ",k

j=lcm(m,n)

print " lcm= ",j

mdgcd=m/k

ndgcd=n/k

print " m=m/gcd =",mdgcd

print " n=n/gcd =",ndgcd

d=gcd(mdgcd,ndgcd)

print " gcd = ",d

Running the gcd.py program:

$ python gcd.py 200560490130 3451796661527379

m= 200560490130

n= 3451796661527379

gcd(m,n)= 9582441

lcm(m,n)= 72246104125768042470

m= m/gcd = 20930

n= n/gcd = 360221019

gcd(m,n) = 1

9 Modular Arithmetic

Let m and n be integers. By definition

m mod(n)

is the remainder of m/n. So if

m = qn+ k,

with k < n, we writem mod(n) = k.

The integers can be separated into equivalence classes with the equivalencerelation (a, b) (we write also a ∼ b), where a and b are equivalent iff thereexist an integer k such that

a− b = kn.

19

Page 20: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

That is, a is equivalent to b iff a and b differ by a multiple of n. Then a isequivalent to b if

a mod(n) = b mod(n).

This is an equivalence relation defined to be a relation that satisfies thefollowing three properties.

(1) (a,a), since a− a = 0n(2) If (a,b), then a− b = kn, so b− a = −kn thus (b,a).(3) If (a, b) and (b, c) then there exists a k1 and a k2 so that a− b = k1n

and b− c = k2n. Thus

a− c = (a− b) + (b− c) = k1n+ k2n = (k1 + k2)n.

So ( a,c)Every integer is equivalent to exactly one integer between 0 and n − 1.

Thus for example

((a+ b)′ + c)′ ∼ (a + b+ c)′ ∼ (a + (b+ c)′)′,

where by (a+ b)′ we mean addition mod n. So addition in In is associative.Similar arguments show that the integers mod n, In, form a ring. The integersmod n are commonly written as either Zn or In.Here is an addition table for the integers mod 5.

+ 0 1 2 3 40 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

Here is a multiplication table for the integers mod 5

× 0 1 2 3 40 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

20

Page 21: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Proposition An integer m in In, has a multiplicative inverse iff m and n arerelatively prime.Proof As a consequence of the Euclidean algorithm, the GCD of n and mcan be written as

GCD(n,m) = αm+ βn,

for some integers α and β. So if n and m are relatively prime then thereexists α and β so that

1 = αm+ βn.

But this means that α is the multiplicative inverse of m in In.On the other hand, if α is the multiplicative inverse of m, then there

exists a β so that1 = αm+ βn.

If m and n had a factor greater than 1 in common, say k, then we wouldhave the fraction

1

k= α

m

k+ β

n

k= αm1 + βn1,

equal to an integer. Thus m and n are relatively prime.Now every integer 1, 2, 3, ..., n− 1 is relatively prime to n if and only if n

is prime. Thus the ring In is a field iff n is prime.Here is an addition table for the integers mod 10.

+ 0 1 2 3 4 5 6 7 8 90 0 1 2 3 4 5 6 7 8 91 1 2 3 4 5 6 7 8 9 02 2 3 4 5 6 7 8 9 0 13 3 4 5 6 7 8 9 0 1 24 4 5 6 7 8 9 0 1 2 35 5 6 7 8 9 0 1 2 3 46 6 7 8 9 0 1 2 3 4 57 7 8 9 0 1 2 3 4 5 68 8 9 0 1 2 3 4 5 6 79 9 0 1 2 3 4 5 6 7 8

Notice that the following multiplication table for the integers mod 10, showsthat the numbers 2, 4, 5, 6, 8, which are not relatively prime to 10, do nothave multiplicative inverses. For example, in the row for multiplication by 2,

21

Page 22: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

we see there is no occurrence of 1. This means nothing times 2 gives 1, andso 2 has no inverse.Here is a multiplication table for the integers mod 10.

× 0 1 2 3 4 5 6 7 8 90 0 0 0 0 0 0 0 0 0 01 0 1 2 3 4 5 6 7 8 92 0 2 4 6 8 0 2 4 6 83 0 3 6 9 2 5 8 1 4 74 0 4 8 2 6 0 4 8 2 65 0 5 0 5 0 5 0 5 0 56 0 6 2 8 4 0 6 2 8 47 0 7 4 1 8 5 2 9 6 38 0 8 6 4 2 0 8 6 4 29 0 9 8 7 6 5 4 3 2 1

The numbers that are relatively prime to 10, namely 1, 3, 7, 9 do form amultiplicative group, because they do all have multiplicative inverses. Andalso if two numbers are each relatively prime to third number m, then theproduct is also relatively prime to m. This is because the product still hasno factors in common with m. However, this subset of numbers 1, 3, 7, 9 doesnot form a group under addition. For example 1 + 1 = 2, which not in thesubset 1, 3, 7, 9.

The φ function is the number of relative primes to 10, that are less than10,

φ(10) = 10(1− 1/2)(1− 1/5) = 4,

2 and 5 being the primes that divide 10. These numbers 1, 3, 7, 9 are calledthe reduced residue system mod 10, and are written Z∗

10, and form a multi-plicative group, that is they have inverses and are closed.

If m and n are equal mod(k), then m − n is divisible by k. If j is anyinteger, then jm and jn are equal mod(k), because the difference jm− jn =j(m − n) is a multiple of k. But the opposite is not true, if jm and jn areequal mod(k), then m and n are not necessarily equal mod(k). This canbe seen from the multiplication table above. For example, 6 × 7 = 2 and6× 2 = 2, yet 7 does not equal 2. If k is a prime, then Ik is a field, and thecancellation law does hold.The cancellation law does not hold in general for Ik, the ring of integers mod

22

Page 23: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

k. It does hold if k is prime.Proposition. If r is the remainder on division of a by b, then

(a, b) = (b, r).

Proof. Supposea = kb+ r.

From this (b, r) divides a. Because it also divides b, it thus divides (a, b). Wehave

r = a− kb,

and so because (a, b) divides both a and b, it divides r. Therefore (a, b)divides both b and r, so (a, b) divides (b, r). Obviously two positive integersthat divide each other are equal. It follows that (a, b) = (b, r)

10 The Euler Totient Function

The word totient comes from a Latin word meaning ”so many”, and is pro-nounced to rhyme with quotient. The Euler Totient function, also called theφ(n) function is a function on the set of positive integers, so that φ(n) is thenumber of positive integers less than n, that are relatively prime to n. Recallthat two integers are relatively prime if their gcd, (m,n) = 1. If p is a prime,then (1, p) = 1, so 1 is counted by the φ function.

If p is prime then no numbers less than p have a prime factor that is aprime factor of p. Therefore we have the following theorem.Theorem. If p is prime, then

φ(p) = p− 1.

Theorem. If p is a prime then

φ(pk) = pk−1(p− 1).

Proof. This follows because if we list all of the integers from 1 to p we have

1, 2, 3, ..., p, p+ 1, p+ 2, ..., 2p, ..., pk

So one has repeatedly p−1 integers that are equivalent to 1, 2, 3, 4, ..., (p−1)mod(p), followed by a multiple of p. This repeating occurs pk/p = pk−1 times.

23

Page 24: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

So all of these integers are relatively prime to pk except for the multiples ofp. It follows that there are pk−1(p− 1) of these numbers. So

φ(pk) = pk−1(p− 1).

So for example consider p = 32. The list of numbers are

1, 2, 3, 4, 5, 6, 7, 8, 9.

So the relatively prime numbers to 32 = 9, skipping the multiples of 3, are

1, 2, 4, 5, 7, 8

Soφ(32) = 31(3− 1) = 6.

We write j|m to mean integer j divides integer m.

Theorem. If j|m, j|k and k = ℓmod(m), then j|ℓ.Proof. If j|m and j|k, then for some q1, q2

m = q1j

andk = q2j.

If k = ℓmod(m), then for some q3

ℓ = k + q3m = q2j + q3q1j.

Corollary. If k is relatively prime tom and ℓ = kmod(m), then ℓ is relativelyprime to m.Theorem. If m and n are relatively prime, then

φ(mn) = φ(m)φ(n).

Proof. Display the numbers 1, 2, 3, 4, ....., mn as an m by n matrix A, thefirst row being

1, 2, 3, 4.....n

the secondn+ 1, n+ 2, n+ 3, n+ 4.....2n

24

Page 25: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

and so on. In the first row, φ(n) of these numbers are relatively prime to n.Consider the element A(1, k) in the first row that is relatively prime to n.Every element of the kth column is equal mod(n) to A(1, k) by the nature ofmatrix A. By the preceding corollary, every element of the kth column of Ais relatively prime to n.

In a given column k, the elements A(1, k), A(2, k), ..., A(m, k) are dis-tinct mod(mn), because m and n are relatively prime allowing application ofthe cancellation law. So they are equivalent to 1, 2, 3, 4, 5, 6, ..., m mod(m).Therefore there are exactly φ(m) in each column that are relatively prime tom. So there are φ(m)φ(n) relatively prime to both m and n.Note. Obviously this result does not hold if m and n are not relativelyprime. For example let m = 4 and n = 6 then φ(m) = 2 and φ(n) = 1, butφ(24) = 8.Corollary If

n =k∏

j=1

pnj

j ,

where p1, p2, ...pk are primes, then

φ(n) =k∏

j=1

φ(pnj

j ).

=k∏

j=1

pnj−1j (pj − 1).

= n

∏kj=1(pj − 1)∏k

j=1 pj.

φ(n) = n∏

p|n

(1−1

p).

The last product is over all of the primes p that divide n.The equation

φ(n) = n∏

p|n

(1−1

p).

is derived directly in Apostol using the Mobius function.

25

Page 26: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

11 Decimal Expansions

Consider the number

77/13 = 5.923076923076923076923076923076

where the infinitely repeating digits are underlined. These repeating digitsform the number

p = 923076.

We can write the number as an integer plus a number less than 1.

77/13 = 5 + 12/13

This number can be written as a continued fraction

77/13 = [5, 1, 12] = 5 + 1/(1 + 1/(12))

A continued fraction that is written as

[a1, a2, a3, a4, ..., an]

meansa1 + 1/(a2 + 1/(a3 + 1/(a4 + 1/(......))))

Letx = 12/13.

Thenx = .923076923076923076923076923076923076923076

1000000x = 923076 + x.

So999999x = 923076

So thatx = 923076/999999.

We havegcd(923076, 999999) = 76923.

26

Page 27: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Dividing by the gcd, we reclaim the fraction

x = 12/13.

Using this method of finding the rational number corresponding to an in-finitely repeating decimal, we will always find a rational number with de-nominator whose digits are all nines. So it must be true that every numbern divides some number of the form

999...9︸ ︷︷ ︸

r

= 10r − 1,

for some r. To show this let m = n− 1. So m/n is a repeating decimal lessthan 1 of say r digits, with the first digit > 1 . Let a number p be the integerformed by the repeating digits. Let m/n = x, then

10rx = p+ x

Thenx = p/(10r − 1) = m/n

Sonp = m(10r − 1)

So n divides m(10r − 1), but n does not divide m, so n divides (10r − 1).Notice that for a rational number m/n, the number r of repeating digits in itsdecimal expansion must be less than n. This follows because in calculatingeach digit in its decimal expansion there will be a remainder that can be zeroor a number between 1 and n−1. As soon as one of these remainders repeatsthen the digits will repeat. so there can be only n− 1 digits before a repeat.The maximum number of repeating digits can occur as in

1/7 = 0.142857142857142857142857142857,

where there are 6 repeated digits.

12 Fermat’s Theorem

Fermat’s theorem says that if two integers a and m are relatively prime, araised to the power of φ(m) is equal to 1 mod(m).

27

Page 28: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Fermat’s Theorem. If a and m are relatively prime, then

aφ(m) = 1 mod(m).

Proof Let R be the reduced residue multiplicative group consisting of theelements of Im that are relatively prime to m. There are φ(m) elements of R,say R = {r1, ..., rφ(m)}. Because a and m are relatively prime, a ∈ R. HenceR = {ar1, ..., arφ(m)}. This follows because every element of R has an inverseso that if

ari = arj

then ri = rj, so i = j. Hence for each i there exists a j so that ari = rj .Multiplying the φ(m) such equations together, we get

aφ(m)r1r2...rφ(m) = r1r2...rφ(m),

from which we get thataφ(m) = 1 mod(m).

Example. Let a = 9 and m = 100. Then

φ(100) = 100(1− 1/2)(1− 1/5) = 100(1/2)(4/5) = 40.

aφ(m) = 940 = 147808829414345923316083210206383297601,

which is 1 mod 100.

13 Fermat’s Little Theorem

Fermat’s little theorem is a Corollary to Fermat’s theorem. If m is a primein Fermat’s Theorem then we get Fermat’s Little Theorem.Fermat’s Little Theorem. If a and p are integers, and p is a prime, then

ap = a mod(p).

Proof Because p is a prime, φ(p) = p− 1 so

ap−1 = 1 mod(p).

Multiplying both sides by a, we get

ap = a mod(p).

28

Page 29: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

14 A Fast Exponential Algorithm for Inte-

gers

Consider computing an integer k raised to the n power, kn. The obviousalgorithm is simply to multiply k times itself n− 1 times, as in 25 = 2 ∗ 2 ∗2 ∗ 2 ∗ 2 = 32. However, consider the case that k is 200 digits long and n isa thousand digits long. The obvious calculation will take quite some time.Let us write this exponential function as f(k, n) = kn. Consider the productoperator ∗ for multiplication in what is called infix notation, then the productof b times c is b ∗ c. By infix we mean that the operator appears betweenthe numbers, which is the normal way of writing arithmetic expressions. Inprefix notation this product would be written as ∗bc, where the operatorcomes first followed by the two numbers, which are to be multiplied. Letus use the letter p as the multiplication operator, s as the square operator,and e as the exponential operator. Then for example in our prefix notationp98 = (9)(8) = 72, s6 = 62 = 36, , and

35 = e3 5 = 243.

We can decompose the exponent 5 into two pieces so that

35 = 3(32)(32) = 3 ∗ (32) ∗ (32).

In our prefix notation this would be written

p3ss3.

We evaluate this step by step from the right, applying the operators in suc-cession

p3ss3

= p3s9

= p3 81

= 243.

Now our fast exponential algorithm will consist in decomposing the expo-nential operator into a prefix stack consisting of just a sequence of symbols,a string made up of a combination of the individual symbols p, s, k, where k

29

Page 30: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

is the number to be raised to the nth power, p is the multiplication operator,and s is the square operator. Now we convert

e(k, n) → ekn,

into an expression involving p, s, e, where the new e expression has a smallerexponent. In fact we divide the exponent by 2 at each step. There are twocases, namely where n is even, and where n is odd. In the case that n iseven, we translate

kn → ekn

tokn/2kn/2 = sek(n/2)

So for example if n = 1024, then

k1024 = ek(1024) = sek(512)

The parentheses are there to indicate that anything surrounded by parenthe-ses is a single symbol, so (n/2) is the actual number obtained immediately,not three symbols n, , and 2, and (1024) means the single number 1024 notthe four numbers 1,0,2,4. That is, the division operator does not appear inthe symbol stack, this division by two is done immediately before the resultis placed in the stack.

In the case that n is odd, 2 does not divide n evenly so we have a remainderof 1. So we need to multiply additionally by the number k, so

ekn = pksek(n/2).

So for example if n = 1023 we have

k1023 = ek(1023) = pksek(511).

Now we continue this conversion until we reach an exponential ek0 = k0 = 1Then we evaluate our expression in the stack from right to left obtaining thevalue of kn, with a very very much smaller amount of arithmetic than in thesimple minded algorithm of multiplying k by itself n− 1 times.

A Scheme version of this function, which is recursive, that is, it calls itself,is used in the next section in a prime test. It is

30

Page 31: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

(define (fast-exp b n)

(cond ((= n 0 ) 1 )

((even? n) (square (fast-exp b (/ n 2))))

(else (* b (fast-exp b (- n 1))))))

The line with the ”cond” word in it is a kind ”if” command, which herereturns 1 if the exponent is zero, or else goes to the next two lines handlingdivision by 2 and the recursive call.

Note that the conversion of the calculation, to a stack expression, andthen its evaluation right to left, is handled by the scheme interpreter itself.

15 A Scheme Program to Test For a Number

Being Prime

This Scheme program comes from the book, Abelson, Harold and Sussman,Gerald J., Structure and Interpretation of Computer Programs.

See Fermat’s Theorem on p89 of Elementary Theory of Numbers, byHarriet Griffin, McGraw-Hill, 1954.

If a and m are relatively prime then aφ(m) = 1mod(m), where φ is theEuler φ functions, the number of integers less than m and relatively primeto m. If p is prime then φ(p) = p − 1, so ap−1 = 1mod(p) or ap = amod(p).This is Fermat’s little theorem.

See file fermat-test.cs in the scheme directory.Here are the Scheme functions for the Fermat test of a prime using Fer-

mat’s little theorem, Abbelson and Sussman p42. So

(fermat-test n) returns #t if n is a prime, #f if n is not a prime

The Function fermat-test uses subfunctions:square (square x), squares xfast-exp, (fast-exp b n), raises b to the nth powerexpmod, (expmod b e m), raises b to power e mod mDefinitions:

(define (square x) ( * x x))

31

Page 32: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

(define (fast-exp b n)

(cond ((= n 0 ) 1 )

((even? n) (square (fast-exp b (/ n 2))))

(else (* b (fast-exp b (- n 1))))))

(define (expmod b e m)

(cond ((= e 0) 1 )

((even? e)

(remainder (square (expmod b (/ e 2) m)) m))

(else

(remainder (* b (expmod b (- e 1) m ))

m))))

(define (fermat-test n)

(define a (+ 2 (random (- n 2))))

(= (expmod a n n) a))

Picking 47 randomly as a positive integer less than 97, the followingfunction must return 47 if 97 is a prime according to Fermat’s little theorem.

(remainder (fast-exp 47 97) 97)

Now if we are using k to test n for being a prime in Fermat’s little theorem,if k is not returned then n can not be a prime. However, if the function doesreturn k, it is very very likely that n is a prime, but not certain. So forexample

77105 = 77mod(105),

even though 105 is not a prime. But trying more random k values addsevidence that n is prime. So

32105 = 92mod(105),

so 105 is not a prime. It would be worth while to test how often this falsedetection of a prime might occur, to get some estimate of the probability ofsuch occurrence.

For example

32

Page 33: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

(fermat-test 9973)

returns #t,

(fermat-test 10000)

returns #f

Now this function fermat-test uses a random number generator suppliedby scheme. This function is (random k) which supplies a integer in theinterval [0, k] (maybe not including 0 or k, check this). However, some kindof pseudo random generator is being used by scheme, which can generateonly a finite number of possibilities. So if k is larger than the number ofpossibilities, there is a problem. In that case use Fermat’s little theoremdirectly, and supply your own random number a to check for n being prime

(expmod a n n)

and check that the result is a. Now if the supplied a is greater thann, then if n is a prime, then the result b will not agree with a because thereturned number will be in the interval [0, n−1] while a is not. But of courseb = a mod(n).

See Fermat’s Theorem on p89 of Elementary Theory of Numbers, byHarriet Griffin, McGraw-Hill, 1954.

If a and m are relatively prime then aφ(m) = 1mod(m), where φ is theEuler φ function, the number of integers less than m and relatively prime tom. If p is prime then φ(p) = p − 1, so ap−1 = 1mod(p) or ap = amod(p).This is Fermat’s little theorem.

16 A Python Program to Test For a Number

Being Prime

# primetest.py 3/30/13

import random

#+ function factorial

def factorial(n):

if(n == 0):

return 1

33

Page 34: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

return n*factorial(n-1)

#+ function remainder of m divided by n, so m mod(n)

def remainder(m,n):

q=m/n

return m - q*n

#+ function square

def square(n):

return n*n

#+ function fexp fast exponential function, that is, fast pow(m,n)

def fexp(m,n):

#print " entering fexp, n= ",n

if(n == 0):

return 1

if(remainder(n,2) == 0):

# n is even

#print " n is even "

return square(fexp(m,n/2))

else:

# n is odd

#print " n is odd "

return m*square(fexp(m,n/2))

#+ isprime Is an integer prime, using Fermat’s little theorem.

def isprime(n,k):

# test an integer n for being prime

# repeat fermat’s test k times for, selecting a random a at each step.

v=True

for j in range(1,k):

a = random.randint(2, n)

m=fexp(a,n)

r=remainder(m,n) # r= m mod(n)

# a^n = a mod(n) if n is a prime.

if (a!=r):

34

Page 35: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

v=False

break

return v

#program main

print " d=a^n mod(n)\n"

n1=1097

n2=1154

print " primes between ", n1," and ",n2

for n in range(n1,n2):

v=isprime(n,10)

if v:

print n, " is prime"

print "primes\n"

print "101 103 107 109 113 127 131 137 139 149\n"

print "151 157 163 167 173 179 181 191 193 197 199\n"

print "881 883 887 907 911 919 929 937\n"

print "941 947 953 967 971 977 983 991\n"

print "997 1009 1013 1019 1021 1031 1033 1039\n"

print "1049 1051 1061 1063 1069 1087 1091 1093\n"

print "1097 1103 1109 1117 1123 1129 1151 1153\n"

print "1163 1171 1181 1187 1193 1201 1213 1217\n"

17 Carmichael Numbers

Using the Python program of the previous section, I found a problem withthe number 1105. The test always found this number to be a prime no matterhow many values of a that I used. So finally I tested for all of the numberswith program

carmichael1105.py

It turns out that 1105 is a special number, called a Carmichael numberor pseudoprime. This is a number such that the Fermat prime test fails forevery number ”a.” 1105 is the second Charmichael number. That 561 is aCarmichael number can be seen with Korselt’s criterion. Indeed, n = 561 is

35

Page 36: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

square free, and for each of the prime factors k of n, k − 1 divides n− 1. So

561 = 3 · 11 · 17

and 2|560, 10|560 and 16|560.The next six Carmichael numbers are (sequence A002997 in OEIS):

1105 = 5 · 13 · 17 (4 | 1104; 12 | 1104; 16 | 1104)

1729 = 7 · 13 · 19 (6 | 1728; 12 | 1728; 18 | 1728)

2465 = 5 · 17 · 29 (4 | 2464; 16 | 2464; 28 | 2464)

2821 = 7 · 13 · 31 (6 | 2820; 12 | 2820; 30 | 2820)

6601 = 7 · 23 · 41 (6 | 6600; 22 | 6600; 40 | 6600)

8911 = 7 · 19 · 67 (6 | 8910; 18 | 8910; 66 | 8910).

8911 = 7 · 19 · 67 (6 | 8910; 18 | 8910; 66 | 8910).

18 Fermat’s Last Theorem

We can find three integers x, y, z (called Pythagorean triples) so that

x2 + y2 = z2.

So for example32 + 42 = 52 = 25

and52 + 122 = 132 = 169.

Fermat’s last theorem says that

xn + yn = zn

36

Page 37: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

has no solution in integers for n > 2.This has recently been proved by the English mathematician Andrew

Wiles. See Simon Singh’s documentary of Andrew Wiles’ extraordinarysearch for a proof: Youtube, Horizon: Fermat’s Last Theorem

Topics related to Wiles proof: The Taniyama-Shimura conjecture, ellipticcurves of algebraic geometry, modular forms, and functions in the complexplane with elaborate symmetries.

19 Mersenne Primes

In modern mathematical usage, a Mersenne number is any number that isone less than a power of two,

Mn = 2n − 1,

where n is a positive integer greater than 1. They are named after the Frenchmonk Marin Mersenne (September 8,1588 to September 1, 1648), who studiedthem in the early 17th century.

Mersenne numbers were in the past defined as numbers of the form

2p − 1,

only when p is a prime. Mersenne primes are Mersenne numbers that areprimes. The following numbers are Mersenne primes

22 − 1 = 3 = 11b

23 − 1 = 7 = 111b

25 − 1 = 31 = 11111b

27 − 1 = 127 = 1111111b.

AMersenne number is represented as a string of 1’s in binary. A necessarycondition for 2n−1 to be prime is for n itself to be prime. But this conditionis not a sufficient condition. Although 11 is a prime number

211 − 1 = 2047 = 23 · 89.

37

Page 38: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

To show this necessary condition, consider the homogeneous polynomialof degree n− 1 in the variables x and y, of the form.

f(x, y) = xn−1 + xn−2y + xn−3y2 + ... + yn−1.

This polynomial is homogeneous because all terms are of the same degree,in this case degree n− 1. Multiplying by x− y we have

(x− y)f(x, y) = (x− y)(xn−1 + xn−2y + xn−3y2 + ... + yn−1)

= (xn + xn−1y + xn−2y2 + ...+ xyn−1)

−(xn−1y + xn−2y2 + ... + xyn−1 + yn)

= xn − yn.

So we obtain the identity

xn − yn = (x− y)(xn−1 + xn−2y + xn−3y2 + ... + yn−1).

We can use this identity to show that if n is a composite number, thenthe Mersenne number

2n − 1,

is not a prime.

Proposition. The number 2n − 1 is not a prime if n is not a prime.

Proof. Suppose n = jk is the product of two positive integers j and k,both greater than 1. Let x = 2j and y = 1 in the identity

xk − yk = (x− y)(xk−1 + xk−2y + xk−3y2 + ...+ yk−1).

Thenxk = 2n,

andyk = 1,

so that

2n − 1 = (2j − 1)(2j(k−1) + 2j(k−2) + 2j(k−3)1 + ...+ 1),

38

Page 39: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

is a product of two integers, each greater than 1, which proves the proposition.

As of August 2008, only 44 Mersenne primes were known; the largestknown prime number (232,582,657 − 1) is a Mersenne prime and in moderntimes the largest known prime has nearly always been a Mersenne prime.Like several previous Mersenne primes, it was discovered by a distributedcomputing project on the Internet, known as theGreat Internet MersennePrime Search (GIMPS). GIMPS reported the finding of a potential 45thMersenne prime on 2008-08-23, and a potential 46th on 2008-09-06. GIMPSnow reports that two independent verifications of each potential M(p) primeconfirm them as prime. An announcement about both primes will be madearound 2008-09-17. Given the delay, chances are at least one of these hasover 10 million decimal digits.

From the identity

(xn − yn) = (x− y)(xn−1 + xn−2y ++xn−3y2 + ... + yn−1),

we can write

2mn − 1 = (2m − 1)(2m(n−1) + 2m(n−2) + 2m(n−3) + 1).

It follows that if a Mersenne number is a prime, then it must be of the form

2p − 1,

where p is a prime.There are 48 known Mersenne primes as of February 2013.

n p Mp digits Date Discoverer Method1 2 3 1 430BCE Greeks ...2 3 7 1 430BCE Greeks ...3 5 31 2 300BCE Greeks ...4 7 127 3 300BCE Greeks ...5 13 8191 4 1456 Anonomous Trail Division6 17 131071 6 1588 Pietro Cataldi Trial Division7 19 524287 6 1588 Pietro Cataldi Trial Division8 31 2147483647 10 1772 Euler Trial Division9 61 2305843009213693951 19 1883 I. M. Pervushin Lucus Sequences17 2281 446087557...132836351 687 Oct 1952 Raphael Robinson LLT SWAC48 57,885,161 581887266...724285951 17,425,170 Jan 25,2013 Curtis Cooper GIMPS PC

This last prime number is also the largest known prime number.

39

Page 40: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

20 The Chinese Remainder Theorem

Suppose we wish to compute an integer x that satisfies

x = 2 mod(5)

x = 3 mod(7)

andx = 4 mod(11)

The integers x − 2, x − 3, and x − 4 must simultaneously divisible by 5,7,and 11. Let K be the product of 5,7, and 11. Dividing K = 385 by each of5,7, and 11 we get respectively

K1 = 77,

K2 = 55,

K3 = 35.

We have (77, 5) = 1, so 77 has an inverse in I5, namely 3. We have (55, 7) = 1,so 55 has an inverse in I7, namely 6. We have (35, 11) = 1, so 35 has aninverse in I11, namely 6. Consider

x = (2)(77)(3) + (3)(55)(6) + (4)(35)(6) = 2292.

Now in mod( 5) the first term is 2, because (77)(3)=1, and the last two termsare zero, because 55 and 35 are multiples of 5. Similarly x is 3 mod (7), andx is 4 mod (11).The Chinese Remainder Theorem Let k1, k2, ..., kn be positive integers.If ki and kj are relatively prime for each i 6= j, the n equations

x = a1 mod(k1)

x = a2 mod(k2)

...

x = an mod(kn)

have a unique integer solution.

40

Page 41: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

Proof. Let K = k1...kn be the product of the k′is. For each ki define

Ki = K/ki. Then Ki and ki are relatively prime, thus Ki has an inverse K ′i

in Iki. Writex = a1K1K

′1 + a2K2K

′2 + ...+ anKnK

′n.

In Ik1x = a1 + 0...+ 0 = a1,

because K1K′1 = 1 and k1 is a factor of the other terms. Thus

x = a1 mod(k1).

The other equations are satisfied by x similarly. To calculate K ′i, calculate

the gcd of Ki and k1, namely, (Ki, ki) = 1, and in the process numbers sothat

1 = αKi + βki.

Then select a number K ′i from the set {1, 2, 3, ..., ki− 1} that is congruent to

α.See Apostol for applications of the Chinese Remainder Theorem.

21 Wilson’s Theorem

If p is a positive prime integer, then

(p− 1)! + 1 = 0 mod p,

or (p− 1)! + 1 is divisible by p.

Equivalently(p− 1)! = −1 mod p.

For example, if p = 7 then (p − 1)! + 1 = 721, and 721/7 = 103, so 721 isdivisible by 7.

From Wikipedia ”The theorem was first discovered by the Iraqi mathe-matician Ibn al-Haytham (known as Alhazen in Medieval Europe) circa 1000AD, but it is named after John Wilson (a student of the English mathemati-cian Edward Waring) who stated it in the 18th century.[1] Waring announcedthe theorem in 1770, although neither he nor Wilson could prove it. Lagrangegave the first proof in 1773. There is evidence that Leibniz was also awareof the result a century earlier, but he never published it.”

41

Page 42: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

22 Hardy’s Cab Number

1729 = 123 + 13 = 93 + 103.

23 Quadratic Residues

Ifx2 = a mod(m),

has a solution, then a is called a quadratic residue of m.

24 Diophantine Equations

Diophantine (die oh fan tine) equations are equations that are to be solvedby integers.

Diophantus of Alexandria is thought to have been born in the interval[201, 215] AD, and is said to have lived to be about 84, so he would have diedsomewhere in the interval [285, 399] AD.

How many ways can 25 dollars be specified in x 5 dollar bills and y 2dollar bills:

5x+ 2y = 25.

# ways of making 25 dollars with 2 and 5 dollar bills

n5=5

n2=12

w=0

for i in range(0,n5+1):

for j in range(0,n2+1):

s=5*i+2*j

if(s == 25):

w=w+1

print " 5’s =",i," 2’s =",j

print " ways=",w

Running dollars.py

42

Page 43: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

5’s = 1 2’s = 10

5’s = 3 2’s = 5

5’s = 5 2’s = 0

ways= 3

The gcd of 5 and 2, (5,2) is 1. So there exists integers x and y so that

5x+ 2y = 1

The set of the form 5x+ 2y is the set

S = {5x+ 2y : x ∈ N, y ∈ N}

Choosing x = 0, we see that all integer multiples of 2 are in this set. Simi-larly all integer multiples of 5 are in this set. Let L be the smallest positiveinteger that is in this set. Then L is the gcd of 2 and 5, namely (2,5)=1.Thus the set of the form 5x+ 2y is the set of all integers N .

Here is another diophantine equation that is much harder to solve:

x3 + y3 = z3.

Theorem. The linear Diophantine equation ax + by = n has a solution ifand only if the greatest common divisor of a and b divides n.

See Griffen

25 Goldbach’s Conjecture

Goldbach’s conjecture is an open problem in mathematics. The conjecture is,that any even integer greater than 2, can be written as a sum of two primes.For example

4 = 2 + 2

6 = 3 + 3

8 = 3 + 5

10 = 3 + 7

43

Page 44: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

12 = 7 + 5

............

24 = 11 + 13

............

............

(FromWikipedia) On 7 June 1742, the Prussian mathematician ChristianGoldbach wrote a letter to Leonhard Euler (letter XLIII) [2] in which heproposed the following conjecture:

Every integer greater than 2 can be written as the sum of three primes.He considered 1 to be a prime number, a convention subsequently abandoned.A modern version of Goldbach’s original conjecture is:

Every integer greater than 5 can be written as the sum of three primes.Euler, becoming interested in the problem, replied by noting that this con-jecture is equivalent to another version:

Every even integer greater than 2 can be written as the sum of two primes,adding that he regarded this an entirely certain theorem (”ein ganz gewissesTheorema”), despite being unable to prove it.

26 Casting Out Nines

What is the number 352648 mod(9) (that is, what is the remainder upondivision by 9)? If a number is divisible by 9, then the number mod 9 is zero,because the remainder is zero. For the same reason if n = n1 + n2 and n2 isdividible by 9, then

nmod 9 = n1mod 9.

We have

352648 = 3(100000) + 5(10000) + 2(1000) + 6(100) + 4(10) + 8.

So we can rewrite it as

(352648 = 3(99999+1)+5(9999+1)+2(999+1)+6(99+1)+4(9+1)+8)mod 9

= (3+5+2+6+4+8+(3∗99999+5 ∗9999+2 ∗999+6∗99+4∗ 9))mod 9

44

Page 45: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

= ((3 + 5 + 2) + 6 + 4 + 8)mod 9

= (1 + 6 + 4 + 8)mod 9

= ((1 + 6 + 4) + 8)mod 9

= (2 + 8)mod 9

= ((2 + 8))mod 9

= 1mod 9

Indeed352648− 9 ∗ 39183 = 1

Proposition. If n is an integer, then

nmod 9 = smod 9,

where s is the sum of the digits of n.

So as in the previous example if n = 352648, then the sum of the digits is3 + 5+ 2+ 6+ 4+ 8, and you can evaluate this mod 9 by adding digits fromthe left until the sum exceeds 9, then subtract 9 and keep the remainder,(that is cast out nines), and continue in this way to the end of the summing.

If an arithmetical calculation is correct in ordinary arithmetic, then it iscorrect mod 9 also, which by the above procedure is simple and can be donein your head. This can be used to check calculations. This was taught in theschools back when calculations were done by hand, rather than by machines(adding machines, cash registers, or computers). I suppose this could bedone very rapidly with the skill that comes with practice. So if you werecalculating a product of two large numbers, you could replace the two largenumbers by their mod 9 values, multiply then together, mod 9, and checkfor agreement with the mod 9 value of the product.

27 The Riemann Zeta Function

Riemann’s zeta function is defined as the complex function

ζ(s) =∞∑

n=1

1

ns,

45

Page 46: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

for the real part of s greater than 1. The definition is extended to thewhole complex plane by analytic continuation. The Riemann zeta functionis analytic everywhere except at s = 1 where it has a simple pole with residue1. The Riemann zeta function has a role in the analytic proof of the primenumber theorem. See Apostol.

28 The Riemann Hypothesis

In a memoir published in 1859 Riemann stated that the nontrivial zeroesof ζ(s) all lie on the vertical line in the complex plane that passes through(1/2,0). It has not yet been proved.

29 The Sieve of Eratosthenes

The Sieve of Eratosthenes is an algorithm for finding a list of prime numbers.It goes as follows.

Given a list of the first n positive integers, we can find all of the primesin the list by first crossing off all multiples of 2. Then the first number after2 that is not crossed off is a prime number namely 3. Now we cross off allnumbers in the list after 3, that are multiples of three. Then the first numberin the list not yet crossed off is a prime, namely 5, then cross of all numbersin the list greater than 5 that are multiples of 5. If we continue this processuntil any multiple of the last prime is greater than n, then we have found allthe primes in the list.

Eratosthenes of Cyrene (276 to 194 BC), created this Algorithm to findall prime numbers less than n. Also Eratosthenes was the first to measure thecircumference of the earth and was the head of the library at Alexandria. Acomputer algorithm is limited to the largest size integer that can be stored,commonly to the largest positive 32 bit integer.A sieve of Eratosthenes program:

// sieve.cpp sieve of eratosthenes of Cyrene (276 to 194 BC)

// Algorithm to find all prime numbers less than n.

// Eratosthenes was the first to measure the

// circumference of the earth. He was the head of the

// library at Alexandria.

46

Page 47: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

// 3/20/2013

// 7/7/97

#include <iostream.h>

main(int argc,char **argv){

const int na=1000000;

char a[na];

int i,k,n,j,m,n1,n2,ik;

int prevp,twinp,twinp1,twinp2;

//All indices of a, where a has value p (p: prime numbers),

//are potential primes.

//Computes all primes <= n

if(argc < 2){

printf("Sieve of Eratosthenes of Cyrene (276 to 194 BC).\n");

printf("This is an Algorithm to find all prime numbers less than n.\n");

printf("Eratosthenes was the first to measure the circumference \n");

printf("of the earth. He was the head of the library at Alexandria.\n");

printf("\n");

printf("sieve.cpp: James D. Emery, Version 3/20/13 \n");

printf("Print each of the prime integers p in the interval (n1,n2),\n");

printf("where 1 <= n1 < p < n2 <= 1,000,000 ,\n");

printf("and n1 and n2 are supplied on the command line. \n");

printf("If only one integer is supplied, we take it to be n2,\n");

printf("and set n1=1 by default. \n");

printf("Usage: sieve n1 n2 (or, sieve n2) \n");

exit(0);

}

if(argc > 2){

n1=atol(argv[1]);

n2=atol(argv[2]);

if((n1 < 1) || (n2 > na)){

cout << " Interval is out of range. ";

exit(0);

}

}

else{

n1=1;

n2=atol(argv[1]);

47

Page 48: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

if(n2 > na){

cout << " Interval is out of range. ";

exit(0);

}

}

// n=na-1;

for(i=0;i<n2;i++){

a[i]=’p’;

}

k=2;

//The k in the while test here is a prime.

while(k < n2){

m=n2/k;

if(m == 1)break;

//set all multiples of k to c (c: composite numbers)

for(i=2;i<=m;i++){

ik=i*k;

if(ik<n2){

a[ik]=’c’;

}

}

//Find the next index of the array where

//the value is p. This index is a prime.

k++;

while(a[k] == ’c’)k++;

}

//print the primes

j=0;

prevp=2;

for(i=n1+1;i<n2;i++){

if(i == n1+1){

twinp=0;

}

if(a[i]==’p’){

48

Page 49: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

if(j == 0)prevp=-1;

cout << " \t" << i;

j++;

if(i == 3){

if(prevp == i-1){

twinp++;

twinp1=i-1;

twinp2=i;

// cout << " \n twin primes " << twinp1 << " " << twinp2 << "\n";

}

}

else{

if(prevp == i-2){

twinp++;

twinp1=i-2;

twinp2=i;

// cout << " \n twin primes " << twinp1 << " " << twinp2 << "\n";

}

}

//Write a newline after 8 prime numbers have been printed.

if(j%8 == 0){

cout << endl;

}

prevp=i;

}

}

cout << " \n Number of primes between " << n1 << " and " << n2 << " = " << j <<

cout << " \n Number of pairs of twin primes between " << n1 << " and " << n2 <<

cout << " \n The last pair of twin primes less than " << n2 << " = " << twinp1<<

return 0;

}

49

Page 50: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

30 Perfect Numbers

A perfect number is a positive integer equal to the sum of its positive divisors,so the first is 6,

6 = 1 + 2 + 3,

the second is 28,28 = 1 + 2 + 4 + 7 + 14

The next two are 496 and 8128.

31 Twin Primes

Twin primes are prime numbers differing by two. It is not known if there arean infinite number of twin primes. This is a famous open problem. Here area few twin primes:

3 5

5 7

17 19

29 31

41 43

59 61

71 73

101 103

107 109

137 139

149 151

179 181

191 193

227 229

281 283

311 313

347 349

419 421

431 433

461 463

521 523

50

Page 51: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

569 571

599 601

617 619

641 643

809 811

827 829

857 859

881 883

32 Analytic Number Theory

Analytic number theory is a subject that uses Real and Complex Analysis(Calculus) to prove number theoretic theorems such as the prime numbertheorem.

33 Repeating Decimals

Using long division we know that any fraction or rational number has an infi-nite decimal representation with eventual repeating decimals. Let us considerthe reverse problem of determining the fraction from the decimal expansion.We also discussed this above in the section called Decimal Expansions.We repeat here a similar analysis in a slightly less detailed form.

Leta = .1234123412341234...

have the four repeating decimals 1234. Show that

a = 1234/9999.

We havea− a/10000 = .1234 = 1234/10000

soa(1− 1/10000) = 1234/10000

So multiplying by 10000

a(10000− 1) = 1234,

51

Page 52: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

soa = 1234/9999.

This can be generalized to the following. If a has n repeating decimals,d1d2d3....dn, that is

a = .d1d2d3....dnd1d2d3....dn...,

then

a =d1d2d3....dn999...999

,

where the denominator has n digits, each a 9.

34 Appendix, Primes Less Than 100002 3 5 7 11 13 17

19 23 29 31 37 41 43 47

53 59 61 67 71 73 79 83

89 97 101 103 107 109 113 127

131 137 139 149 151 157 163 167

173 179 181 191 193 197 199 211

223 227 229 233 239 241 251 257

263 269 271 277 281 283 293 307

311 313 317 331 337 347 349 353

359 367 373 379 383 389 397 401

409 419 421 431 433 439 443 449

457 461 463 467 479 487 491 499

503 509 521 523 541 547 557 563

569 571 577 587 593 599 601 607

613 617 619 631 641 643 647 653

659 661 673 677 683 691 701 709

719 727 733 739 743 751 757 761

769 773 787 797 809 811 821 823

827 829 839 853 857 859 863 877

881 883 887 907 911 919 929 937

941 947 953 967 971 977 983 991

997 1009 1013 1019 1021 1031 1033 1039

1049 1051 1061 1063 1069 1087 1091 1093

1097 1103 1109 1117 1123 1129 1151 1153

1163 1171 1181 1187 1193 1201 1213 1217

1223 1229 1231 1237 1249 1259 1277 1279

1283 1289 1291 1297 1301 1303 1307 1319

1321 1327 1361 1367 1373 1381 1399 1409

1423 1427 1429 1433 1439 1447 1451 1453

1459 1471 1481 1483 1487 1489 1493 1499

1511 1523 1531 1543 1549 1553 1559 1567

1571 1579 1583 1597 1601 1607 1609 1613

1619 1621 1627 1637 1657 1663 1667 1669

1693 1697 1699 1709 1721 1723 1733 1741

52

Page 53: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

1747 1753 1759 1777 1783 1787 1789 1801

1811 1823 1831 1847 1861 1867 1871 1873

1877 1879 1889 1901 1907 1913 1931 1933

1949 1951 1973 1979 1987 1993 1997 1999

2003 2011 2017 2027 2029 2039 2053 2063

2069 2081 2083 2087 2089 2099 2111 2113

2129 2131 2137 2141 2143 2153 2161 2179

2203 2207 2213 2221 2237 2239 2243 2251

2267 2269 2273 2281 2287 2293 2297 2309

2311 2333 2339 2341 2347 2351 2357 2371

2377 2381 2383 2389 2393 2399 2411 2417

2423 2437 2441 2447 2459 2467 2473 2477

2503 2521 2531 2539 2543 2549 2551 2557

2579 2591 2593 2609 2617 2621 2633 2647

2657 2659 2663 2671 2677 2683 2687 2689

2693 2699 2707 2711 2713 2719 2729 2731

2741 2749 2753 2767 2777 2789 2791 2797

2801 2803 2819 2833 2837 2843 2851 2857

2861 2879 2887 2897 2903 2909 2917 2927

2939 2953 2957 2963 2969 2971 2999 3001

3011 3019 3023 3037 3041 3049 3061 3067

3079 3083 3089 3109 3119 3121 3137 3163

3167 3169 3181 3187 3191 3203 3209 3217

3221 3229 3251 3253 3257 3259 3271 3299

3301 3307 3313 3319 3323 3329 3331 3343

3347 3359 3361 3371 3373 3389 3391 3407

3413 3433 3449 3457 3461 3463 3467 3469

3491 3499 3511 3517 3527 3529 3533 3539

3541 3547 3557 3559 3571 3581 3583 3593

3607 3613 3617 3623 3631 3637 3643 3659

3671 3673 3677 3691 3697 3701 3709 3719

3727 3733 3739 3761 3767 3769 3779 3793

3797 3803 3821 3823 3833 3847 3851 3853

3863 3877 3881 3889 3907 3911 3917 3919

3923 3929 3931 3943 3947 3967 3989 4001

4003 4007 4013 4019 4021 4027 4049 4051

4057 4073 4079 4091 4093 4099 4111 4127

4129 4133 4139 4153 4157 4159 4177 4201

4211 4217 4219 4229 4231 4241 4243 4253

4259 4261 4271 4273 4283 4289 4297 4327

4337 4339 4349 4357 4363 4373 4391 4397

4409 4421 4423 4441 4447 4451 4457 4463

4481 4483 4493 4507 4513 4517 4519 4523

4547 4549 4561 4567 4583 4591 4597 4603

4621 4637 4639 4643 4649 4651 4657 4663

4673 4679 4691 4703 4721 4723 4729 4733

4751 4759 4783 4787 4789 4793 4799 4801

4813 4817 4831 4861 4871 4877 4889 4903

4909 4919 4931 4933 4937 4943 4951 4957

4967 4969 4973 4987 4993 4999 5003 5009

5011 5021 5023 5039 5051 5059 5077 5081

5087 5099 5101 5107 5113 5119 5147 5153

5167 5171 5179 5189 5197 5209 5227 5231

5233 5237 5261 5273 5279 5281 5297 5303

5309 5323 5333 5347 5351 5381 5387 5393

53

Page 54: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

5399 5407 5413 5417 5419 5431 5437 5441

5443 5449 5471 5477 5479 5483 5501 5503

5507 5519 5521 5527 5531 5557 5563 5569

5573 5581 5591 5623 5639 5641 5647 5651

5653 5657 5659 5669 5683 5689 5693 5701

5711 5717 5737 5741 5743 5749 5779 5783

5791 5801 5807 5813 5821 5827 5839 5843

5849 5851 5857 5861 5867 5869 5879 5881

5897 5903 5923 5927 5939 5953 5981 5987

6007 6011 6029 6037 6043 6047 6053 6067

6073 6079 6089 6091 6101 6113 6121 6131

6133 6143 6151 6163 6173 6197 6199 6203

6211 6217 6221 6229 6247 6257 6263 6269

6271 6277 6287 6299 6301 6311 6317 6323

6329 6337 6343 6353 6359 6361 6367 6373

6379 6389 6397 6421 6427 6449 6451 6469

6473 6481 6491 6521 6529 6547 6551 6553

6563 6569 6571 6577 6581 6599 6607 6619

6637 6653 6659 6661 6673 6679 6689 6691

6701 6703 6709 6719 6733 6737 6761 6763

6779 6781 6791 6793 6803 6823 6827 6829

6833 6841 6857 6863 6869 6871 6883 6899

6907 6911 6917 6947 6949 6959 6961 6967

6971 6977 6983 6991 6997 7001 7013 7019

7027 7039 7043 7057 7069 7079 7103 7109

7121 7127 7129 7151 7159 7177 7187 7193

7207 7211 7213 7219 7229 7237 7243 7247

7253 7283 7297 7307 7309 7321 7331 7333

7349 7351 7369 7393 7411 7417 7433 7451

7457 7459 7477 7481 7487 7489 7499 7507

7517 7523 7529 7537 7541 7547 7549 7559

7561 7573 7577 7583 7589 7591 7603 7607

7621 7639 7643 7649 7669 7673 7681 7687

7691 7699 7703 7717 7723 7727 7741 7753

7757 7759 7789 7793 7817 7823 7829 7841

7853 7867 7873 7877 7879 7883 7901 7907

7919 7927 7933 7937 7949 7951 7963 7993

8009 8011 8017 8039 8053 8059 8069 8081

8087 8089 8093 8101 8111 8117 8123 8147

8161 8167 8171 8179 8191 8209 8219 8221

8231 8233 8237 8243 8263 8269 8273 8287

8291 8293 8297 8311 8317 8329 8353 8363

8369 8377 8387 8389 8419 8423 8429 8431

8443 8447 8461 8467 8501 8513 8521 8527

8537 8539 8543 8563 8573 8581 8597 8599

8609 8623 8627 8629 8641 8647 8663 8669

8677 8681 8689 8693 8699 8707 8713 8719

8731 8737 8741 8747 8753 8761 8779 8783

8803 8807 8819 8821 8831 8837 8839 8849

8861 8863 8867 8887 8893 8923 8929 8933

8941 8951 8963 8969 8971 8999 9001 9007

9011 9013 9029 9041 9043 9049 9059 9067

9091 9103 9109 9127 9133 9137 9151 9157

9161 9173 9181 9187 9199 9203 9209 9221

9227 9239 9241 9257 9277 9281 9283 9293

54

Page 55: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

9311 9319 9323 9337 9341 9343 9349 9371

9377 9391 9397 9403 9413 9419 9421 9431

9433 9437 9439 9461 9463 9467 9473 9479

9491 9497 9511 9521 9533 9539 9547 9551

9587 9601 9613 9619 9623 9629 9631 9643

9649 9661 9677 9679 9689 9697 9719 9721

9733 9739 9743 9749 9767 9769 9781 9787

9791 9803 9811 9817 9829 9833 9839 9851

9857 9859 9871 9883 9887 9901 9907 9923

9929 9931 9941 9949 9967 9973

35 Fibonacci Numbers

See Jim Emery Fibonacci Numbers and the Golden Ratio, fibonacci.tex,fibonacci.pdf .

36 Carl Fredich Gauss. The Prince of Math-

ematicians

(30 April 1777 23 February 1855)1801: Disquisitiones Arithmeticae (Latin). A German translation by H.

Maser Untersuchungen ber hhere Arithmetik (Disquisitiones Arithmeticaeand other papers on number theory) (Second edition). New York: Chelsea.1965. ISBN 0-8284-0191-8, pp. 1453. English translation by Arthur A.Clarke Disquisitiones Arithemeticae (Second, corrected edition). New York:Springer. 1986. ISBN 0-387-96254-9.

55

Page 56: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

37 Bibliography

[1] Abelson, Harold and Sussman, Gerald J., Structure and Interpreta-tion of Computer Programs, The MIT Press, McGraw-Hill, 1985.

[2] Apostol Tom, Introduction to Analytic Number Theory, Springer-Verlag, 1976.

[3] Emery James D., Cryptography, stem2.org/je/crypto.pdf.

[4] Gauss, Carl Friedrich, Disquisitiones Arithmeticae. Translated byArthur A. Clarke, Yale University Press, 1966. (QA241 .G28 1870 ) (Gauss1777-1855 1966).

[5] Griffin Harriet, Elementary Theory of Numbers, McGraw-Hill, 1954.

[6] Kranakis Evangelos, Primality and Cryptography, B. G. Teubner,Stuttgart, 1986,kck.

56

Page 57: Number Theory - Stem2 · 22 Hardy’s Cab Number 42 23 Quadratic Residues 42 24 Diophantine Equations 42 ... A proof can be found in the book on Analytic Number Theory by Tom Apostle

38 Index

euclidean algorithm 5fundamental theorem of arithmetic 3modular ring Zp 9relatively prime 3

57