PRIME NUMBERS We denote by N the set of natural numbers: 1,2

PRIME NUMBERS
YANKI LEKILI
We denote by N the set of natural numbers: 1,2, . . . ,
These are constructed using Peano axioms. We will not get into the philosophical questions related to this and simply assume the usual properties of natural numbers: There is
an addition and multiplication law on numbers. These satisfy the commutative, associative
and distributive laws. There is an order on N so that either a < b or b < a for distinct
natural numbers. Furthermore, every non-empty set in N has a smallest element, i.e. the
order on N is a well-ordering. Finally, we shall appeal to the principle of mathematical
induction.
We write Z for all integers: {. . . , −2, −1, 0, 1, 2, . . .} and Z≥0 for non-negative integers.
1. Divisibility
Definition 1. An integer a is divisible by b if there is a third integer c such that
a = bc
We write b | a if b divides a and b - a if b does not divide a.
The relation | is reflexive, a | a; transitive, b | a and c | b implies c | a, but not symmetric,
if b | a then it is not usually the case that a | b. In fact, if b and a are positive integers and
b | a, then we have b ≤ a.
Definition 2. A positive integer p is said to be a prime number (or simply a prime) if
p > 1 and p has no positive divisors except 1 and p.
The first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, . . .
The primes are the “building blocks” of numbers. The following theorem makes this
precise:
Theorem 3. Every positive integer except 1 is a product of primes.
Proof. Let n ∈ N be a number. Either n is prime, when there is nothing to prove or n has
divisors between 1 and n. Let S be the set of divisors of n greater than 1. Then this set
has a smallest element m. We claim that m is a prime. Otherwise, there would be natural
number l with 1 < l < m such that l | m but since m | n, by transitivity, we have that
l | n. We obtained an element of S, namely l, that is smaller than the smallest element of
S. This is a contradiction. Hence, m must have been a prime. Therefore, n is either prime
or divisible by a prime less than n, say p1 in which case,
n = p1 n1 , 1 < n1 < n
1
2
YANKI LEKILI
Here n1 is either a prime, in which case the proof is completed or it is divisible by a prime
p2 , in which case, we have
n = p1 n1 = p1 p2 n2 ,
1 < n2 < n1 < n
Repeating the argument, we obtain a sequence of decreasing numbers n, n1 , . . . , nk−1 , . . .
The sequence stops when nk is prime for some k, and then we have:
n = p1 p2 . . . pk
Note that pi ’s in the above proof do not have to be distinct, we can group them together
and write:
n = pe11 pe22 . . . pess
to get the prime factorisation of the integer n. For example, we have:
666 = 2.32 .37
We will see later that the factors pei i are unique apart from rearrangement of factors. But,
first we need to develop our understanding of division a little more.
Lemma 4. (Division Algorithm) Given a ∈ Z and b > 0, there exists a unique q, r ∈ Z
such that a = qb + r and 0 ≤ r < b.
Proof. Consider the arithmetic progression
. . . , a − 3b, a − 2b, a − b, a, a + b, a + 2b, a + 3b . . .
extending indefinitely in both directions. Let S be the set of nonnegative elements in
this list. S is non-empty: Either a is nonnegative then a ∈ S, or if a is negative,then
a − ab = a(1 − b) ≥ 0 hence a − ab ∈ S. Now, S is non-empty, hence has a smallest element
r. Thus, by definition, we have r = a − qb for some q and r ≥ 0. Also r < b because
otherwise r − b = a − (q + 1)b would be an element of S that is smaller than r.
Next, to prove uniqueness, let a = q1 b + r1 = q2 b + r2 satisfying the same conditions.
Then (q1 − q2 )b = r2 − r1 . Taking absolute values, we get |q1 − q2 |b = |r2 − r1 |, hence
b | |r2 − r1 |, but 0 ≤ r1 , r2 < b hence |r2 − r1 | < b. Hence, it must be that |r2 − r1 | = 0 and
|q2 − q1 | = 0. In other words, r1 = r2 and q1 = q2 .
Definition 5. Let a, b ∈ N. The greatest common divisor of a and b is the greatest number
d ∈ N such that d | a and d | b. We write (a, b) (or gcd(a, b)) for the greatest common
divisor of a and b . The numbers a and b are said to be coprime (or relatively prime) if
(a, b) = 1.
For example, by listing all divisors of 12 and all divisors of 8, one can easily compute
(12, 8) = 4 but soon we will do this in a much more efficient way.
Theorem 6. If d = (a, b) then there exists integers x0 and y0 such that
d = (a, b) = ax0 + by0
PRIME NUMBERS
3
Another way to state this fundamental result is that the greatest common divisor of a
and b is a Z-linear combination of a and b.
Proof. Consider the set S of all natural numbers of the form ax + by with x and y in Z.
The set is non-empty, for example it contains a and b. Hence, S has a smallest element m.
So m is a natural number of the form m = ax0 + by0 for some integers x0 and y0 . Every
common divisor of a and b divides m, hence in particular d | m. To conclude that d = m,
we shall show that m | a and m | b. Using the division algorithm, write a = qm + r for
0 ≤ r < m. Let x0 = (1 − qx0 ) and y 0 = −qy0 . Then, we have
ax0 + by 0 = a − qax0 − qby0 = a − qm = r
Hence, by the minimality property of m it follows that r = 0. This shows that m | a,
similarly we show that m | b.
Note that the integers x0 , y0 are not uniquely determined. Indeed, given one solution
(x0 , y0 ) to d = ax0 + by0 , we can obtain infinitely many other solutions as:
d = a(x0 + nb) + b(y0 − na) for n ∈ Z.
The previous theorem gives a characterization of the greatest common divisor of a and b.
Namely, it is least positive integer value of ax + by where x and y ranges over all integers.
But how to compute this value? (and the integers x0 , y0 ? )
We shall use Euclid’s algorithm. The crucial observation is the following lemma:
Lemma 7. If a = qb + r then (a, b) = (b, r).
Proof. If d is a common divisor of a and b, then d | a − qb = r, hence d is a common divisor
of b and r. Conversely, if d is a common divisor of b and r, then d | qb + r = a, hence d
is a common divisor of a and b. Therefore, the set of common divisors of a and b agree
with the set of common divisors of b and r, hence the greatest common divisors are the
same.
Now, given a, b ∈ N, Euclid’s algorithm works as follows to determine (a, b). Without
loss of generality, suppose b < a, then we apply division algorithm to write a = q1 b+r1 with
0 ≤ r1 < b. If r1 6= 0, then we apply division algorithm to b and r1 to write b = q2 r1 + r2
with 0 ≤ r2 < r1 . We repeat this until we find a remainder which is zero. (This must
happen at some finite step, since b > r1 > r2 . . . ≥ 0. Thus, we have a system of equations:
a = q1 b + r1 , 0 < r1 < b
b = q2 r1 + r2 , 0 < r2 < r1
r1 = q3 r2 + r3 , 0 < r3 < r2
..
.
rn−3 = qn−1 rn−2 + rn−1 , 0 < rn−1 < rn−2
rn−2 = qn rn−1 + rn , 0 < rn < rn−1
rn−1 = qn rn + 0.
4
YANKI LEKILI
We apply the above lemma repeatedly to deduce
(a, b) = (b, r1 ) = (r1 , r2 ) = . . . = (rn−2 , rn−1 ) = (rn−1 , rn ) = (rn , 0) = rn
Thus, we proved:
Theorem 8. The last non-zero remainder rn of Euclid’s algorithm is the greatest common
divisor of a and b.
Here is an example. Let us compute (187, 35). We have
187 = 5.35 + 12
35 = 2.12 + 11
12 = 1.11 + 1
11 = 11.1
Thus, we see that (187, 35) = 1. Thus, we should be able to find integers x0 and y0 such
that
187x0 + 35y0 = 1
Euclid’s algorithm also gives a way to do this. Namely, we have
1 = 12 − 1.11
1 = 12 − 1.(35 − 2.12)
1 = 187 − 5.35 − 1.(35 − 2.(187 − 5.35)) = 3.187 − 16.35
Indeed, one can use Euclid’s algorithm to give another proof of Theorem 6.
We will now return back to factorisations of natural numbers into primes. We start with
the following:
Theorem 9. (Euclid’s first theorem) Let p be a prime number and let a1 , a2 ∈ N. If
p | a1 a2 then p | a1 or p | a2 . More generally, if a prime p divides a product a1 a2 . . . an ,
then p divides ai for some i.
Proof. The case of a product with n factors follows easily from the case with two factors.
Suppose p is a primes and p | a1 a2 . If p - a1 then (a1 , p) = 1 and therefore, by Theorem
6, there are an x0 and a y0 for which
x0 a1 + y0 p = 1
Multiplying this by a2 gives
x0 a1 a2 + y0 pa2 = a2
Now, p | x0 a1 a2 and p | y0 pa2 , hence p | a2 .
Let’s use this to prove a theorem due to Pythagoras.
√
Theorem 10. 2 is irrational.
PRIME NUMBERS
5
√
√
Proof. If 2 is rational, we can write it as 2 = ab for integers a, b such that (a, b) = 1.
Then, a and b satisfy the equation:
a2 = 2b2
Hence, b | a2 . Therefore, p | a2 for any prime factor p of b. It follows from Theorem 9 that
p | a. But, this is contrary to the assumption that (a, b) = 1. Hence b = 1, and this also is
clearly false.
We now come to one of the main tools of elementary number theory:
Theorem 11. (Fundamental theorem of arithmetic) Every positive integer a > 1 has
a factorisation into prime factors as a = pe11 pe22 . . . pess , and apart from rearrangement of
factors, this factorisation is unique.
Proof. We have already seen the existence of a factorisation in Theorem 3. Now, we show
uniqueness.
Suppose that a = p1 . . . pk = q1 . . . qj are two prime factorisations of a. Then, by
Theorem 9, p1 |qi1 for some i1 . Since qi1 is a prime, this implies that p1 = qi1 . We can then
divide out p1 and qi1 from both sides to get two prime factorisations of a/p1 = p2 . . . pk =
q1 . . . qi1 −1 qi1 +1 . . . qj . We can then match p2 with qi2 for some i2 by the same argument.
Continuing this way, we get that for all s, ps = qis for some is . After cancelling out all of
p1 , p2 , . . . pk , the remaining product must equal 1. Hence, there are no remaining factors
on the right hand side either. Hence k = j and the matching p1 = qi1 , p2 = qi2 , . . . pk = qik
shows that the two factorisations differ by only a rearrangement of factors.
It is now clear why 1 should not be counted as a prime. If it were, then Theorem 11
would be false, since we could insert any number of unit factors.
If we know the prime factorisation of positive integer a then we can immediately write
down all positive divisors: if a = pe11 pe22 . . . pekk then b|a if and only if b has a prime factorisation of the form b = pf11 pf22 . . . pfkk with 0 ≤ fi ≤ ei for all i. This observation gives the
following lemma:
Lemma 12. If m, n ∈ N are coprime then every natural number d with d | mn can be
written uniquely as d = d1 d2 where d1 , d2 ∈ N and d1 | m and d2 | n.
Proof. Since m and n are coprime, they don’t have any prime factors in common. So,
kr+1
kr+s
m = pk11 . . . pkr r and n = pr+1
. . . pr+s
where all the pi are distinct. If d | mn then
lr+1
lr+s
lr+s
l1
d = p1 . . . pr+s with 0 ≤ li ≤ ki for 1 ≤ i ≤ r + s. Let d1 = pl11 . . . plrr and d2 = pr+1
. . . pr+s
.
Then obviously d = d1 d2 , d1 | m and dr | n.
l0
l0
Conversely, if d = d01 d02 , d01 | m and d02 | n then we mush have d01 = p11 . . . prr and
0
0
lr+1
lr+s
d02 = pr+1
. . . pr+s
. From d = d01 d02 it follows that li = li0 for 1 ≤ i ≤ r + s and therefore
0
d1 = d1 and d2 = d02 . This shows uniqueness.
We will also need the following lemma.
Lemma 13. If p1 , p2 . . . pr be distinct prime numbers and let n be any integer. If pi | n for
all i then p1 p2 . . . pr | n.
6
YANKI LEKILI
Proof. For every r ≥ 1, we must show the following statement: If p1 , p2 . . . , pr are distinct
primes, n is any integer and pi | n for i = 1, 2, . . . , r, then p1 p2 . . . pr | n. To do this, we
use induction on r. The case r = 1 is obviously true. Now assume r ≥ 2 and that we have
shown the statement for r − 1. Let p1 . . . , pr be distinct primes and n an integer such that
pi | n for all i. By induction hypothesis, we get that p1 p2 . . . pr−1 | n. So, we can write
n = p1 p2 . . . pr−1 m for some m ∈ Z. Now, since pr | n and pr - pi for 1 ≤ i ≤ r − 1, it
follows, by Theorem 9, that pr | m. Hence, it follows that p1 p2 . . . pr | p1 p2 . . . pr−1 m = n
as desired.
Exercise: Give an alternative proof of Lemma 13 using FTA.
Finally, let us discuss factorials and their prime factorisations. Recall that given a
natural number N , we have the notation:
N ! := ΠN
i=1 i = 1.2 . . . (N − 1).N
This number is equal to the number of permutations of a set of N elements.
Let us observe that if p | N !, then p must divide one of the numbers 1, 2, . . . , N and
therefore p ≤ N . On the other hand, every prime number p ≤ N obviously is a prime
factor of N !. So, to find a prime factorisation of N !, we need to determine the exponent
of each prime p ≤ N which divides N !. Let us write this first as:
N ! = Πp≤N pep
where the product is over all p ≤ N and ep are non-negative integers.
To state the next result, we find convenient to introduce the following notation:
Definition 14. For any real number x ∈ R, one signifies by [x] the largest integer ≤ x,
that is, the unique integer such that x − 1 < [x] ≤ x. This function is called the integral
part of x.
P
N
Lemma 15. N ! = Πp≤N pep where ep = ∞
m=1 [ pm ]
P
N
m
Note that the sum ∞
m=1 [ pm ] has only finitely many non-zero terms because if p > N ,
then [ pNm ] = 0.
Proof. Consider a prime number p ≤ N . We must count how often p appears in the
product N ! = 1.2. · · · .N . Clearly, [ Np ] of the factors 1, 2, . . . , N are multiples of p; [ pN2 ]
factors are multiples of p2 etc. Hence, in ep = [ Np ] + [ pN2 ] + . . . we have counted once the
number of factor which are divisible by p but not p2 (as part of [ Np ]), we have counted twice
the number of factors which are divisible by p2 but not p3 (as part of [ Np ] + [ pN2 ]) etc. This
completes the proof.
Note that it follows easily from above that
ep ≤ [
for the sum
P∞
N
m=1 [ pm ] <
P∞
N
m=1 pm
= N ( p1 +
N
]
p−1
1
p2
+ . . .) =
N
.
p−1
PRIME NUMBERS
7
As an example, let us find the largest integer k such that 7k | 50!. We can compute this
as:
50
50
k = [ ] + [ 2 ] = 7 + 1 = 8.
7
7
1.1. Computational problems.
√
Lemma 16. A positive integer n is composite if and only if n has a prime divisor p ≤ n
Proof. If n is composite then n = ab with 1 < a < n and 1 < b < n. We can assume
√ that
a
≤
b.
Let
p
be
a
prime
factor
of
a.
Then
p
is
also
a
prime
factor
of
n
and
p
≤
a
=
a.a ≤
√
√
a.b = n.
A primality test is an algorithm that determines whether an integer n > 1 is √
a prime
or composite. The above lemma gives the following test. For every prime√p ≤ n test
whether n is divisible by p or not. We know that if p|n for some p ≤ n then n is
composite, otherwise n is prime.
The sieve of Eratosthenes is the method of computing list of primes up to a number n
by using this algorithm. Write down all the integers n and cross out multiples of 2, then
√
cross out multiples of 3 and continue until we cross out multiples of all primes p ≤ n.
Then the remaining numbers are prime.
This method is useful for small numbers but, of course, it is clear that it is not very
efficient for large numbers. In 2002, Agrawal, Kayal and Saxena developed the first polynomial time primality test (known as the AKS primality test). Polynomial time means that
there exists constants C, k such that for every integer n > 1 the algorithm needs at most
C.(log n)k many steps to decide whether n is prime or not. Note that AKS test determines
whether n is prime or not without finding a prime factor.