Vous êtes sur la page 1sur 53

Number Theory

James Emery
Last Addition or Edit: 6/7/2014

Contents
1 Introduction

2 Prime Numbers

3 The Prime Number Theorem

4 The Euclidean Algorithm for the Greatest Common Divisor

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 Fermats Theorem

27

13 Fermats Little Theorem

28
1

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 Fermats Last Theorem

36

19 Mersenne Primes

37

20 The Chinese Remainder Theorem

40

21 Wilsons Theorem

41

22 Hardys Cab Number

42

23 Quadratic Residues

42

24 Diophantine Equations

42

25 Goldbachs Conjecture

42

26 The Riemann Zeta Function

43

27 The Riemann Hypothesis

43

28 The Sieve of Eratosthenes

43

29 Perfect Numbers

47

30 Twin Primes

47

31 Analytic Number Theory

48

32 Repeating Decimals

49

33 Appendix, Primes Less Than 10000

50

34 Fibonacci Numbers

52

35 Carl Fredich Gauss. The Prince of Mathematicians

53

36 Bibliography

53

Introduction

The Theory of Numbers is that part of mathematics that studies properties


of the counting numbers and the integers. It has generated many of the
concepts of modern Abstract Algebra.

Prime Numbers

A prime number is a positive integer that cannot be written as the product


of 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. This
is 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 that
by the definition every number is relatively prime to 1.
The Fundamental Theorem of Arithmetic says that every positive integer greater than 1, can be written as a product of powers of primes in a
unique way. Thus for example
45 = (2)(32 ),
and
59424750 = (2)(32 )(53 )(74 )(11).
The number 1 is not considered a prime, even though it cannot be written
as a product of two integers each greater than 1.
There are an infinite number of primes. For suppose there are a finite
number of them. Multiply these finite numbers together and add 1. This
3

number is not divisible by any of the finite primes. But a number is either
divisible by a prime, or a prime itself. This is a contradiction. Therefore
there are an infinite number of primes. This argument was given by Euclid.

The Prime Number Theorem

The prime number theorem says that the number of primes less than natural
number n is approximately equal to
n
.
ln(n)
The Prime Number Theorem. If (n) is the number of primes less than
n, then the ratio of (n) to n/ ln(n) goes to 1 as n goes to ,
lim

ln(n)
(n)
n

= 1.

The following table suggests that this is true.


n
101
102
103
104
105
106
107
108
109
1010

(n)
n/ ln(n)
ratio
4
4.3
0.93
25
21.7
1.15
168
144.8
1.16
1,229
1,086
1.13
9,592
8,686
1.10
78,498
72,382
1.08
664,579
620,420
1.07
5,761,455
5,428,681
1.06
50,847,534 48,254,942 1.05
455,052,511 434,394,482 1.048

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


Apostle.

The Euclidean Algorithm for the Greatest


Common Divisor

Given two positive integers b1 and b2 , we shall show how to compute the
gcd. Let us assume that b1 > b2 . We can divide a larger integer by a smaller
one 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. The
remainder 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 with
b1 = k1 b2 + 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, so
b2 > b3 . We may continue this division
b1 = k1 b2 + b3 ,
b2 = k2 b3 + b4
b3 = k3 b4 + b5
....................
bn1 = kn1 bn + bn+1
bn = kn bn+1 + bn+2 ,
until the remainder bn+2 is zero, when the division stops. We have a strictly
decreasing sequence of integers
b1 > b2 > b3 > .... > bn+2 .
5

Eventually we must reach a step n where the remainder bn+2 is zero, where
we cant continue the division. At this point we claim that g = bn+1 is the
greatest common divisor of the integers b1 and b2 .
Going backwards, we have
bn = kn bn+1 ,
bn1 = kn1 bn + bn+1 ,
bn2 = kn2 bn1 + bn ,
....................
b1 = k1 b2 + b3 ,
showing that bn+1 eventually divides b2 and b1 .
Explicitly from the first equation
bn = kn bn+1 ,
we see that bn+1 divides bn . Continuing down the list of equations, we see
that 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 is
the largest common divisor.
So suppose h is any other common divisor. That is suppose that h divides
b1 and b2 . Then from the first equation of the first list above, namely
b1 = k1 b2 + b3 ,
h must divide b3 , and so from the second equation it must divide b4 , and so
on, 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 not
important, because if m=b1 < b2 = n the first step will be
b1 = k1 b2 + 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

The following proposition is a very important one in number theory and


is often used in proofs.
Proposition. Given two integers, b1 2 and b2 2, there exists two
integers 1 and 1 such that the greatest common divisor g is given by
g = 1 b1 + 1 b2 .
Proof. The Euclidean algorithm presented above for the gcd(b1 ,b2 ) = g is
b1 = k1 b2 + b3 ,
b2 = k2 b3 + b4
b3 = k3 b4 + b5
....................
bn2 = kn2 bn1 + bn
bn1 = kn1 bn + g
bn = kn bn+1 .
Solving the next to last equation, equation n 1, for g we have
g = bn1 kn1 bn
We can write this as
g = n1 bn1 + n1 bn ,
where
n1 = 1,
and
n1 = kn1 .
Now consider the division step n 2, where equation n 2 is
bn2 = kn2 bn1 + bn .
Solving for bn , we have
bn = bn2 kn2 bn1
7

Substituting for bn in
g = n1 bn1 + n1 bn ,
we have
g = n1 bn1 + n1 (bn2 kn2 bn1 )
= n1 bn2 + (n1 n1 kn2 )bn1
= n2 bn2 + n2 bn1 ,
where
n2 = n1
and
n2 = n1 n1 kn2
This relationship will be repeated, so that at the pth step we find
g = p bp + p bp+1 ,
where
p = p+1
and
p = p+1 p+1 kp .
So finally
g = 1 b1 + 1 b2 .
Thus by saving the quotients k1 , k2 , ...kn1 we can construct the numbers 1
and 1 .
Corollary. If integers m and n are relatively prime, then m mod(n) has a
multiplicative 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

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 nonzero
element has a multiplicative inverse).
There is a java program gcdex.java in the next section for the calculation
of the gcd, and the numbers and . If the gcd =1, it calculates the
multiplicative inverse of m mod n.
We can find and by hand. At the beginning of this section we
calculated 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 as
6 = 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 their
greatest common divisor (m, n).
Proof. This follows because there exists integers and such that
9

(m, n) = m + n.
Proposition. If r is the remainder on division of a by b, then
(a, b) = (b, r).
Proof. Suppose
a = kb + r.
From this (b, r) divides a. Because it also divides b, it thus divides (a, b). We
have
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 integers
that divide each other are equal. It follows that (a, b) = (b, r)

Python gcd.py Greatest Common Divisor


Program

This program computes the gcd(m,n) of two integers m and n, and computes
numbers 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

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

So these numbers m and n are relatively prime, and = 18825831 is the


multiplicative inverse of m in the ring Zn , because any multiple of n is zero
in 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

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

#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

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

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
int
int
int
int
int
int

b1;
b2;
b3;
na;
nk;
ns;
r;

int alpha;
int beta;
int g;
int j;
int tmp;
nk=100;

15

k = new int[nk];
b1=m;
b2=n;
tmp=b1/b2;
r=b1-tmp*b2;
if(r == 0){
System.out.print(" gcd= "
alpha=0;
beta=1;
g=alpha*b1+beta*b2;

+ b2 + "\n");

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

The Greatest Common Divisor Example in


Scheme

Application. To compute the greatest common divisor (a, b),of two integers 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 actual
gcd function built into Scheme.

The Greatest Common Divisor Example in


Python

This program computes gcdexample(m,n) where the two integers are defined in the program. See also program gcd.py where the integers are defined
as command line parameters. The python program computes with long integers.
#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

#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

#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

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 write
m mod(n) = k.
The integers can be separated into equivalence classes with the equivalence
relation (a, b) (we write also a b), where a and b are equivalent iff there
exist an integer k such that
a b = kn.
19

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


equivalent to b if
a mod(n) = b mod(n).
This is an equivalence relation defined to be a relation that satisfies the
following 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 = k1 n
and b c = k2 n. Thus
a c = (a b) + (b c) = k1 n + k2 n = (k1 + k2 )n.
So ( a,c)
Every integer is equivalent to exactly one integer between 0 and n 1.
Thus for example
((a + b)0 + c)0 (a + b + c)0 (a + (b + c)0 )0 ,
where by (a + b)0 we mean addition mod n. So addition in In is associative.
Similar arguments show that the integers mod n, In , form a ring. The integers
mod n are commonly written as either Zn or In .
Here is an addition table for the integers mod 5.
+
0
1
2
3
4

0
0
1
2
3
4

1
1
2
3
4
0

2
2
3
4
0
1

3
3
4
0
1
2

4
4
0
1
2
3

Here is a multiplication table for the integers mod 5

0
1
2
3
4

0
0
0
0
0
0

1
0
1
2
3
4

2
0
2
4
1
3

3
0
3
1
4
2

4
0
4
3
2
1
20

Proposition An integer m in In , has a multiplicative inverse iff m and n are


relatively prime.
Proof As a consequence of the Euclidean algorithm, the GCD of n and m
can be written as
GCD(n, m) = m + n,
for some integers and . So if n and m are relatively prime then there
exists 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 that
1 = m + n.
If m and n had a factor greater than 1 in common, say k, then we would
have the fraction
1
m
n
= + = m1 + n1 ,
k
k
k
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
9

0
0
1
2
3
4
5
6
7
8
9

1
1
2
3
4
5
6
7
8
9
0

2
2
3
4
5
6
7
8
9
0
1

3
3
4
5
6
7
8
9
0
1
2

4
4
5
6
7
8
9
0
1
2
3

5
5
6
7
8
9
0
1
2
3
4

6
6
7
8
9
0
1
2
3
4
5

7
7
8
9
0
1
2
3
4
5
6

8
8
9
0
1
2
3
4
5
6
7

9
9
0
1
2
3
4
5
6
7
8

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

we see there is no occurrence of 1. This means nothing times 2 gives 1, and


so 2 has no inverse.
Here is a multiplication table for the integers mod 10.

0
1
2
3
4
5
6
7
8
9

0
0
0
0
0
0
0
0
0
0
0

1
0
1
2
3
4
5
6
7
8
9

2
0
2
4
6
8
0
2
4
6
8

3
0
3
6
9
2
5
8
1
4
7

4
0
4
8
2
6
0
4
8
2
6

5
0
5
0
5
0
5
0
5
0
5

6
0
6
2
8
4
0
6
2
8
4

7
0
7
4
1
8
5
2
9
6
3

8
0
8
6
4
2
0
8
6
4
2

9
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 a


multiplicative group, because they do all have multiplicative inverses. And
also if two numbers are each relatively prime to third number m, then the
product is also relatively prime to m. This is because the product still has
no factors in common with m. However, this subset of numbers 1, 3, 7, 9 does
not form a group under addition. For example 1 + 1 = 2, which not in the
subset 1, 3, 7, 9.
The function is the number of relative primes to 10, that are less than
10,
(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 called

the reduced residue system mod 10, and are written Z10
, and form a multiplicative 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 any
integer, 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 are
equal mod(k), then m and n are not necessarily equal mod(k). This can
be seen from the multiplication table above. For example, 6 7 = 2 and
6 2 = 2, yet 7 does not equal 2. If k is a prime, then Ik is a field, and the
cancellation law does hold.
The cancellation law does not hold in general for Ik , the ring of integers mod
22

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. Suppose
a = kb + r.
From this (b, r) divides a. Because it also divides b, it thus divides (a, b). We
have
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 integers
that 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 pronounced 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 the
number of positive integers less than n, that are relatively prime to n. Recall
that 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 a
prime 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 ) = pk1 (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 = pk1 times.
23

So all of these integers are relatively prime to pk except for the multiples of
p. It follows that there are pk1(p 1) of these numbers. So
(pk ) = pk1 (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 = q1 j
and
k = q2 j.
If k = `mod(m), then for some q3
` = k + q3 m = q2 j + q3 q1 j.
Corollary. If k is relatively prime to m and ` = kmod(m), then ` is relatively
prime 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, the
first row being
1, 2, 3, 4.....n
the second
n + 1, n + 2, n + 3, n + 4.....2n
24

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 of
matrix A. By the preceding corollary, every element of the kth column of A
is relatively prime to n.
In a given column k, the elements A(1, k), A(2, k), ..., A(m, k) are distinct mod(mn), because m and n are relatively prime allowing application of
the 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 to
m. 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 relatively
prime. For example let m = 4 and n = 6 then (m) = 2 and (n) = 1, but
(24) = 8.
Corollary If
n=

k
Y

pj j ,

k
Y

(pj j ).

j=1

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


(n) =

j=1

k
Y

n 1

pj j

(pj 1).

j=1

=n

Qk

j=1 (pj
Qk
j=1 pj

(n) = n

1)

1
(1 ).
p
p|n

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


The equation
Y
1
(n) = n (1 ).
p
p|n
is derived directly in Apostol using the Mobius function.

25

11

Decimal Expansions

Consider the number


77/13 = 5.923076923076923076923076923076
where the infinitely repeating digits are underlined. These repeating digits
form 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 ]
means
a1 + 1/(a2 + 1/(a3 + 1/(a4 + 1/(......))))
Let
x = 12/13.
Then
x = .923076923076923076923076923076923076923076
1000000x = 923076 + x.
So
999999x = 923076
So that
x = 923076/999999.
We have
gcd(923076, 999999) = 76923.

26

Dividing by the gcd, we reclaim the fraction


x = 12/13.
Using this method of finding the rational number corresponding to an infinitely repeating decimal, we will always find a rational number with denominator whose digits are all nines. So it must be true that every number n
divides some number of the form
|999...9
{z }

= 10r 1,

for some r. To show this let m = n 1. So m/n is a repeating decimal less


than 1 of say r digits, with the first digit > 1 . Let a number p be the integer
formed by the repeating digits. Let m/n = x, then
10r x = p + x
Then
x = p/(10r 1) = m/n
So
np = 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 its
decimal expansion must be less than n. This follows because in calculating
each digit in its decimal expansion there will be a remainder that can be zero
or a number between 1 and n1. As soon as one of these remainders repeats
then 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

Fermats Theorem

Fermats theorem says that if two integers a and m are relatively prime, a
raised to the power of (m) is equal to 1 mod(m).
27

Fermats 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 the
elements 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. Hence
R = {ar1 , ..., ar(m)} . This follows because every element of R has an inverse
so 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) r1 r2 ...r(m) = r1 r2 ...r(m) ,
from which we get that
a(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

Fermats Little Theorem

Fermats little theorem is a Corollary to Fermats theorem. If m is a prime


in Fermats Theorem then we get Fermats Little Theorem.
Fermats 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
ap1 = 1 mod(p).
Multiplying both sides by a, we get
ap = a mod(p).
28

14

A Fast Exponential Algorithm for Integers

Consider computing an integer k raised to the n power, k n . The obvious


algorithm 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 is
a thousand digits long. The obvious calculation will take quite some time.
Let us write this exponential function as f (k, n) = k n . Consider the product
operator for multiplication in what is called infix notation, then the product
of b times c is b c. By infix we mean that the operator appears between
the numbers, which is the normal way of writing arithmetic expressions. In
prefix notation this product would be written as bc, where the operator
comes first followed by the two numbers, which are to be multiplied. Let
us 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 notation
p98 = (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 succession
p3ss3
= p3s9
= p3 81
= 243.
Now our fast exponential algorithm will consist in decomposing the exponential 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

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 smaller
exponent. In fact we divide the exponent by 2 at each step. There are two
cases, namely where n is even, and where n is odd. In the case that n is
even, we translate
k n ekn
to
k n/2 k n/2 = sek(n/2)
So for example if n = 1024, then
k 1024 = ek(1024) = sek(512)
The parentheses are there to indicate that anything surrounded by parentheses 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 not
the four numbers 1,0,2,4. That is, the division operator does not appear in
the symbol stack, this division by two is done immediately before the result
is placed in the stack.
In the case that n is odd, 2 does not divide n evenly so we have a remainder
of 1. So we need to multiply additionally by the number k, so
ekn = pksek(n/2).
So for example if n = 1023 we have
k 1023 = ek(1023) = pksek(511).
Now we continue this conversion until we reach an exponential ek0 = k 0 = 1
Then we evaluate our expression in the stack from right to left obtaining the
value of k n , with a very very much smaller amount of arithmetic than in the
simple 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

(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 here
returns 1 if the exponent is zero, or else goes to the next two lines handling
division by 2 and the recursive call.
Note that the conversion of the calculation, to a stack expression, and
then 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 Fermats Theorem on p89 of Elementary Theory of Numbers, by
Harriet Griffin, McGraw-Hill, 1954.
If a and m are relatively prime then a(m) = 1mod(m), where is the
Euler functions, the number of integers less than m and relatively prime
to m. If p is prime then (p) = p 1, so ap1 = 1mod(p) or ap = amod(p).
This is Fermats little theorem.
See file fermat-test.cs in the scheme directory.
Here are the Scheme functions for the Fermat test of a prime using Fermats 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 x
fast-exp, (fast-exp b n), raises b to the nth power
expmod, (expmod b e m), raises b to power e mod m
Definitions:
(define (square x) ( * x x))

31

(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 following
function must return 47 if 97 is a prime according to Fermats little theorem.
(remainder (fast-exp 47 97) 97)
Now if we are using k to test n for being a prime in Fermats little theorem,
if k is not returned then n can not be a prime. However, if the function does
return k, it is very very likely that n is a prime, but not certain. So for
example
77105 = 77 mod(105),
even though 105 is not a prime. But trying more random k values adds
evidence that n is prime. So
32105 = 92 mod(105),
so 105 is not a prime. It would be worth while to test how often this false
detection of a prime might occur, to get some estimate of the probability of
such occurrence.
For example
32

(fermat-test 9973)
returns #t,
(fermat-test 10000)
returns #f
Now this function fermat-test uses a random number generator supplied
by scheme. This function is (random k) which supplies a integer in the
interval [0, k] (maybe not including 0 or k, check this). However, some kind
of pseudo random generator is being used by scheme, which can generate
only a finite number of possibilities. So if k is larger than the number of
possibilities, there is a problem. In that case use Fermats little theorem
directly, 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 than
n, then if n is a prime, then the result b will not agree with a because the
returned number will be in the interval [0, n 1] while a is not. But of course
b = a mod(n).
See Fermats Theorem on p89 of Elementary Theory of Numbers, by
Harriet Griffin, McGraw-Hill, 1954.
If a and m are relatively prime then a(m) = 1mod(m), where is the
Euler function, the number of integers less than m and relatively prime to
m. If p is prime then (p) = p 1, so ap1 = 1mod(p) or ap = amod(p).
This is Fermats 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

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 Fermats little theorem.


def isprime(n,k):
# test an integer n for being prime
# repeat fermats 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

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 with
the number 1105. The test always found this number to be a prime no matter
how many values of a that I used. So finally I tested for all of the numbers
with program
carmichael1105.py
It turns out that 1105 is a special number, called a Carmichael number
or pseudoprime. This is a number such that the Fermat prime test fails for
every number a. 1105 is the second Charmichael number. That 561 is a
Carmichael number can be seen with Korselts criterion. Indeed, n = 561 is

35

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):

18

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).

Fermats Last Theorem

We can find three integers x, y, z so that


x2 + y 2 = z 2 .
So for example
32 + 42 = 52 = 25
and
52 + 122 = 132 = 169.
Fermats last theorem says that
xn + y n = z n
36

has no solution in integers for n > 2


This has recently been proved by the English mathematician Andrew
Wiles
See Simon Singhs documentary of Andrew Wiles extraordinary search
for a proof: Youtube, Horizon: Fermats Last Theorem
Taniyama-Shimura conjecture, elliptic curve of algebraic geometry modular forms, functions in the complex plane with elaborate symmetries.

19

Mersenne Primes

In modern mathematical usage, a Mersenne number is any number that is


one less than a power of two,
Mn = 2n 1,
where n is a positive integer greater than 1. They are named after the
French monk Marin Mersenne (September 8,1588 to 1 September 1,1648),
who studied them in the early 17th century.
Mersenne numbers were in the past numbers of the form
2p 1,
where p is a prime. Mersenne primes are Mersenne numbers that are primes.
The following numbers are Mersenne primes
22 1 = 3 = 11b
23 1 = 7 = 111b
25 1 = 31 = 11111b
27 1 = 127 = 1111111b.
A Mersenne number is represented as a string of 1s in binary. A necessary
condition for 2n 1 to be prime is for n itself to be prime. But this condition
is not a sufficient condition. Although 11 is a prime number
211 1 = 2047 = 23 89.

37

To show this necessary condition, consider the homogeneous polynomial


of degree n 1 in the variables x and y, of the form.
f (x, y) = xn1 + xn2 y + xn3 y 2 + ... + y n1.
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)(xn1 + xn2 y + xn3 y 2 + ... + y n1)
= (xn + xn1 y + xn2 y 2 + ... + xy n1 )
(xn1 y + xn2 y 2 + ... + xy n1 + y n )
= xn y n .
So we obtain the identity
xn y n = (x y)(xn1 + xn2 y + xn3 y 2 + ... + y n1).
We can use this identity to show that if n is a composite number, then
the 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 y k = (x y)(xk1 + xk2 y + xk3 y 2 + ... + y k1).
Then
xk = 2n ,
and
y k = 1,
so that
2n 1 = (2j 1)(2j(k1) + 2j(k2) + 2j(k3) 1 + ... + 1),
38

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 largest
known prime number (232,582,657 1) is a Mersenne prime and in modern
times the largest known prime has nearly always been a Mersenne prime.
Like several previous Mersenne primes, it was discovered by a distributed
computing project on the Internet, known as the Great Internet Mersenne
Prime Search (GIMPS). GIMPS reported the finding of a potential 45th
Mersenne prime on 2008-08-23, and a potential 46th on 2008-09-06. GIMPS
now reports that two independent verifications of each potential M(p) prime
confirm them as prime. An announcement about both primes will be made
around 2008-09-17. Given the delay, chances are at least one of these has
over 10 million decimal digits.
From the identity
(xn y n ) = (x y)(xn1 + xn2 y + +xn3 y 2 + ... + y n1),
we can write
2mn 1 = (2m 1)(2m(n1) + 2m(n2) + 2m(n3) + 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
1
2
3
4
5
6
7
8
9
17
48

p
2
3
5
7
13
17
19
31
61
2281
57,885,161

Mp
3
7
31
127
8191
131071
524287
2147483647
2305843009213693951
446087557...132836351
581887266...724285951

digits
1
1
2
3
4
6
6
10
19
687
17,425,170

Date
430BCE
430BCE
300BCE
300BCE
1456
1588
1588
1772
1883
Oct 1952
Jan 25,2013

Discoverer
Greeks
Greeks
Greeks
Greeks
Anonomous
Pietro Cataldi
Pietro Cataldi
Euler
I. M. Pervushin
Raphael Robinson
Curtis Cooper

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

Method
...
...
...
...
Trail Division
Trial Division
Trial Division
Trial Division
Lucus Sequences
LLT SWAC
GIMPS PC

20

The Chinese Remainder Theorem

Suppose we wish to compute an integer x that satisfies


x = 2 mod(5)
x = 3 mod(7)
and
x = 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 of
5,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 an
inverse 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 terms
are zero, because 55 and 35 are multiples of 5. Similarly x is 3 mod (7), and
x 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

Proof. Let K = k1 ...kn be the product of the ki0 s. For each ki define
Ki = K/ki. Then Ki and ki are relatively prime, thus Ki has an inverse Ki0
in Iki . Write
x = a1 K1 K10 + a2 K2 K20 + ... + an Kn Kn0 .
In Ik1
x = a1 + 0... + 0 = a1 ,
because K1 K10 = 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 Ki0 , calculate
the gcd of Ki and k1 , namely, (Ki , ki) = 1, and in the process numbers so
that
1 = Ki + ki.
Then select a number Ki0 from the set {1, 2, 3, ..., ki 1} that is congruent to
.
See Apostol for applications of the Chinese Remainder Theorem.

21

Wilsons 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 is
divisible by 7.
From Wikipedia The theorem was first discovered by the Iraqi mathematician Ibn al-Haytham (known as Alhazen in Medieval Europe) circa 1000
AD, but it is named after John Wilson (a student of the English mathematician Edward Waring) who stated it in the 18th century.[1] Waring announced
the theorem in 1770, although neither he nor Wilson could prove it. Lagrange
gave the first proof in 1773. There is evidence that Leibniz was also aware
of the result a century earlier, but he never published it.
41

22

Hardys Cab Number


1729 = 123 + 13 = 93 + 103 .

23

Quadratic Residues

If
x2 = 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 solved
by integers.

25

Goldbachs Conjecture

Goldbachs 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
12 = 7 + 5
............
24 = 11 + 13
............
............

42

(From Wikipedia) On 7 June 1742, the Prussian mathematician Christian


Goldbach wrote a letter to Leonhard Euler (letter XLIII) [2] in which he
proposed 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 Goldbachs 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 conjecture 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 gewisses
Theorema), despite being unable to prove it.

26

The Riemann Zeta Function

Riemanns zeta function is defined as the complex function


(s) =

1
,
s
n=1 n

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

27

The Riemann Hypothesis

In a memoir published in 1859 Riemann stated that the nontrivial zeroes


of (s) all lie on the vertical line in the complex plane that passes through
(1/2,0). It has not yet been proved.

28

The Sieve of Eratosthenes

The Sieve of Eratosthenes is an algorithm for finding a list of prime numbers.


It goes as follows.
43

Given a list of the first n positive integers, we can find all of the primes
in the list by first crossing off all multiples of 2. Then the first number after
2 that is not crossed off is a prime number namely 3. Now we cross off all
numbers in the list after 3, that are multiples of three. Then the first number
in the list not yet crossed off is a prime, namely 5, then cross of all numbers
in the list greater than 5 that are multiples of 5. If we continue this process
until any multiple of the last prime is greater than n, then we have found all
the primes in the list.
Eratosthenes of Cyrene (276 to 194 BC), created this Algorithm to find
all prime numbers less than n. Also Eratosthenes was the first to measure the
circumference of the earth and was the head of the library at Alexandria. A
computer 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.
// 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");
44

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]);
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;
45

//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){
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";
46

}
}
//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;
}

29

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.

30

Twin Primes

Twin primes are prime numbers differing by two. It is not known if there are
an infinite number of twin primes. This is a famous open problem. Here are
a few twin primes:
3 5
5 7
17 19
29 31
47

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
569 571
599 601
617 619
641 643
809 811
827 829
857 859
881 883

31

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 number
theorem.

48

32

Repeating Decimals

Using long division we know that any fraction or rational number has an infinite decimal representation with eventual repeating decimals. Let us consider
the 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.
Let
a = .1234123412341234...
have the four repeating decimals 1234. Show that
a = 1234/9999.
We have
a a/10000 = .1234 = 1234/10000
so
a(1 1/10000) = 1234/10000
So multiplying by 10000
a(10000 1) = 1234,
so
a = 1234/9999.
This can be generalized to the following. If a has n repeating decimals,
d1 d2 d3 ....dn , that is
a = .d1 d2 d3 ....dn d1 d2 d3 ....dn ...,
then

d1 d2 d3 ....dn
,
999...999
where the denominator has n digits, each a 9.
a=

49

33

Appendix, Primes Less Than 10000

2
3
19 23
53 59
89 97
131
173
223
263
311
359
409
457
503
569
613
659
719
769
827
881
941
997
1049
1097
1163
1223
1283
1321
1423
1459
1511
1571
1619
1693
1747
1811
1877
1949
2003
2069
2129
2203
2267
2311
2377
2423
2503
2579
2657
2693
2741
2801
2861

5
7
29 31
61 67
101
137
179
227
269
313
367
419
461
509
571
617
661
727
773
829
883
947
1009
1051
1103
1171
1229
1289
1327
1427
1471
1523
1579
1621
1697
1753
1823
1879
1951
2011
2081
2131
2207
2269
2333
2381
2437
2521
2591
2659
2699
2749
2803
2879

11 13
37 41
71 73
103
139
181
229
271
317
373
421
463
521
577
619
673
733
787
839
887
953
1013
1061
1109
1181
1231
1291
1361
1429
1481
1531
1583
1627
1699
1759
1831
1889
1973
2017
2083
2137
2213
2273
2339
2383
2441
2531
2593
2663
2707
2753
2819
2887

17
43 47
79 83
107
149
191
233
277
331
379
431
467
523
587
631
677
739
797
853
907
967
1019
1063
1117
1187
1237
1297
1367
1433
1483
1543
1597
1637
1709
1777
1847
1901
1979
2027
2087
2141
2221
2281
2341
2389
2447
2539
2609
2671
2711
2767
2833
2897

109
151
193
239
281
337
383
433
479
541
593
641
683
743
809
857
911
971
1021
1069
1123
1193
1249
1301
1373
1439
1487
1549
1601
1657
1721
1783
1861
1907
1987
2029
2089
2143
2237
2287
2347
2393
2459
2543
2617
2677
2713
2777
2837
2903

113
157
197
241
283
347
389
439
487
547
599
643
691
751
811
859
919
977
1031
1087
1129
1201
1259
1303
1381
1447
1489
1553
1607
1663
1723
1787
1867
1913
1993
2039
2099
2153
2239
2293
2351
2399
2467
2549
2621
2683
2719
2789
2843
2909

50

127
163
199
251
293
349
397
443
491
557
601
647
701
757
821
863
929
983
1033
1091
1151
1213
1277
1307
1399
1451
1493
1559
1609
1667
1733
1789
1871
1931
1997
2053
2111
2161
2243
2297
2357
2411
2473
2551
2633
2687
2729
2791
2851
2917

167
211
257
307
353
401
449
499
563
607
653
709
761
823
877
937
991
1039
1093
1153
1217
1279
1319
1409
1453
1499
1567
1613
1669
1741
1801
1873
1933
1999
2063
2113
2179
2251
2309
2371
2417
2477
2557
2647
2689
2731
2797
2857
2927

2939
3011
3079
3167
3221
3301
3347
3413
3491
3541
3607
3671
3727
3797
3863
3923
4003
4057
4129
4211
4259
4337
4409
4481
4547
4621
4673
4751
4813
4909
4967
5011
5087
5167
5233
5309
5399
5443
5507
5573
5653
5711
5791
5849
5897
6007
6073
6133
6211
6271
6329
6379
6473
6563
6637

2953
3019
3083
3169
3229
3307
3359
3433
3499
3547
3613
3673
3733
3803
3877
3929
4007
4073
4133
4217
4261
4339
4421
4483
4549
4637
4679
4759
4817
4919
4969
5021
5099
5171
5237
5323
5407
5449
5519
5581
5657
5717
5801
5851
5903
6011
6079
6143
6217
6277
6337
6389
6481
6569
6653

2957
3023
3089
3181
3251
3313
3361
3449
3511
3557
3617
3677
3739
3821
3881
3931
4013
4079
4139
4219
4271
4349
4423
4493
4561
4639
4691
4783
4831
4931
4973
5023
5101
5179
5261
5333
5413
5471
5521
5591
5659
5737
5807
5857
5923
6029
6089
6151
6221
6287
6343
6397
6491
6571
6659

2963
3037
3109
3187
3253
3319
3371
3457
3517
3559
3623
3691
3761
3823
3889
3943
4019
4091
4153
4229
4273
4357
4441
4507
4567
4643
4703
4787
4861
4933
4987
5039
5107
5189
5273
5347
5417
5477
5527
5623
5669
5741
5813
5861
5927
6037
6091
6163
6229
6299
6353
6421
6521
6577
6661

2969
3041
3119
3191
3257
3323
3373
3461
3527
3571
3631
3697
3767
3833
3907
3947
4021
4093
4157
4231
4283
4363
4447
4513
4583
4649
4721
4789
4871
4937
4993
5051
5113
5197
5279
5351
5419
5479
5531
5639
5683
5743
5821
5867
5939
6043
6101
6173
6247
6301
6359
6427
6529
6581
6673

2971
3049
3121
3203
3259
3329
3389
3463
3529
3581
3637
3701
3769
3847
3911
3967
4027
4099
4159
4241
4289
4373
4451
4517
4591
4651
4723
4793
4877
4943
4999
5059
5119
5209
5281
5381
5431
5483
5557
5641
5689
5749
5827
5869
5953
6047
6113
6197
6257
6311
6361
6449
6547
6599
6679

51

2999
3061
3137
3209
3271
3331
3391
3467
3533
3583
3643
3709
3779
3851
3917
3989
4049
4111
4177
4243
4297
4391
4457
4519
4597
4657
4729
4799
4889
4951
5003
5077
5147
5227
5297
5387
5437
5501
5563
5647
5693
5779
5839
5879
5981
6053
6121
6199
6263
6317
6367
6451
6551
6607
6689

3001
3067
3163
3217
3299
3343
3407
3469
3539
3593
3659
3719
3793
3853
3919
4001
4051
4127
4201
4253
4327
4397
4463
4523
4603
4663
4733
4801
4903
4957
5009
5081
5153
5231
5303
5393
5441
5503
5569
5651
5701
5783
5843
5881
5987
6067
6131
6203
6269
6323
6373
6469
6553
6619
6691

6701
6779
6833
6907
6971
7027
7121
7207
7253
7349
7457
7517
7561
7621
7691
7757
7853
7919
8009
8087
8161
8231
8291
8369
8443
8537
8609
8677
8731
8803
8861
8941
9011
9091
9161
9227
9311
9377
9433
9491
9587
9649
9733
9791
9857
9929

34

6703
6781
6841
6911
6977
7039
7127
7211
7283
7351
7459
7523
7573
7639
7699
7759
7867
7927
8011
8089
8167
8233
8293
8377
8447
8539
8623
8681
8737
8807
8863
8951
9013
9103
9173
9239
9319
9391
9437
9497
9601
9661
9739
9803
9859
9931

6709
6791
6857
6917
6983
7043
7129
7213
7297
7369
7477
7529
7577
7643
7703
7789
7873
7933
8017
8093
8171
8237
8297
8387
8461
8543
8627
8689
8741
8819
8867
8963
9029
9109
9181
9241
9323
9397
9439
9511
9613
9677
9743
9811
9871
9941

6719
6793
6863
6947
6991
7057
7151
7219
7307
7393
7481
7537
7583
7649
7717
7793
7877
7937
8039
8101
8179
8243
8311
8389
8467
8563
8629
8693
8747
8821
8887
8969
9041
9127
9187
9257
9337
9403
9461
9521
9619
9679
9749
9817
9883
9949

6733
6803
6869
6949
6997
7069
7159
7229
7309
7411
7487
7541
7589
7669
7723
7817
7879
7949
8053
8111
8191
8263
8317
8419
8501
8573
8641
8699
8753
8831
8893
8971
9043
9133
9199
9277
9341
9413
9463
9533
9623
9689
9767
9829
9887
9967

6737
6823
6871
6959
7001
7079
7177
7237
7321
7417
7489
7547
7591
7673
7727
7823
7883
7951
8059
8117
8209
8269
8329
8423
8513
8581
8647
8707
8761
8837
8923
8999
9049
9137
9203
9281
9343
9419
9467
9539
9629
9697
9769
9833
9901
9973

6761
6827
6883
6961
7013
7103
7187
7243
7331
7433
7499
7549
7603
7681
7741
7829
7901
7963
8069
8123
8219
8273
8353
8429
8521
8597
8663
8713
8779
8839
8929
9001
9059
9151
9209
9283
9349
9421
9473
9547
9631
9719
9781
9839
9907

6763
6829
6899
6967
7019
7109
7193
7247
7333
7451
7507
7559
7607
7687
7753
7841
7907
7993
8081
8147
8221
8287
8363
8431
8527
8599
8669
8719
8783
8849
8933
9007
9067
9157
9221
9293
9371
9431
9479
9551
9643
9721
9787
9851
9923

Fibonacci Numbers

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

52

35

Carl Fredich Gauss. The Prince of Mathematicians

(30 April 1777 23 February 1855)


1801: Disquisitiones Arithmeticae (Latin). A German translation by H.
Maser Untersuchungen ber hhere Arithmetik (Disquisitiones Arithmeticae
and 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.

36

Bibliography

[1]Apostol Tom, Introduction to Analytic Number Theory, SpringerVerlag, 1976.


[2]Griffin Harriet, Elementary Theory of Numbers, McGraw-Hill, 1954.
[3]Abelson, Harold and Sussman, Gerald J., Structure and Interpretation of Computer Programs, The MIT Press, McGraw-Hill, 1985.
[4]Kranakis Evangelos, Primality and Cryptography, B. G. Teubner,
Stuttgart, 1986,kck.
[5]Gauss, Carl Friedrich, Disquisitiones Arithmeticae. Translated by
Arthur A. Clarke, Yale University Press, 1966. (QA241 .G28 1870 ) (Gauss
1777-1855 1966).

53

Vous aimerez peut-être aussi