Tony Skyner
Perfect Numbers
1
/
30
Perfect Numbers
Tony Skyner
Level: 3
Credit Points: 10
Supervisor: Dr A.W. Chatters
Date of Handing in: 21
st
January 2005
Word Count:
8623
Number of Pages:
30
Contents
1.
Perfect Numbers
1.1
Introducti
on
1.2
Even Perfect Numbers Results
1.3
Other forms of Perfect Numbers
1.3.1
Odd Perfect Numbers
1.3.2
Multiply perfect numbers
2.
Mersenne Primes
2.1
Historical Interests
2.2
Mersenne Number Results
3.
Primality Testing
3.1
Introduction
3.2
Common tests for Mersenne Primes
3.2.1
Using Fermat’s Little
Theorem
3.2.2
Lucas

Lehmar Test
3.3
The Formula for Primes
3.4
Maple Procedures for Testing Mersenne Numbers
3.4.1
Lucas

Lemar Test
3.4.2
Formula for Primes
3.4.3
Conglomerate of Tests
4.
Appendix

Images
4.1
Lucas

Lemar Test
4.2
Formula for Primes Test
4.3
Other Tests
4.4
Conglomerate of Tests
5.
References
Tony Skyner
Perfect Numbers
2
/
30
Acknowledgement of Sources
For all ideas taken from other sources (books, articles, internet), the source of the ideas is
mentioned in the main text and fully referenced at the end of the report.
All material, which is quoted essentially word

for

word
from other sources, is given in
quotation marks and referenced.
Signed ............................................................. Date...................................
Tony Skyner
Perfect Numbers
3
/
30
Chapter 1: Perfect Numbers
1.1
Introduction
It is not known when Perfect N
umbers where first discovered, or when they were studied.
However, it is thought that they may even have been known to the Egyptians, and may have
even been known before. Although the ancient mathematicians knew of the existence of
Perfect Numbers, it was
the Greeks who took a keen interest in them, especially Pythagoras
and his followers (O’Conner and Robertson, 2004).
The Pythagoreans found the number 6 interesting (more for its mystical and numerological
properties than for any mathematical significance
), as it is the sum of its proper factors, i.e.
6 = 1 + 2 + 3
This is the smallest Perfect Number, the next being 28 (Burton, 1980). These two numbers
also had religious significant ascribed to them, as 6 is the number of days it took the Christian
God to
create the world, and 28 is the number of days in a Lunar Cycle. S
T
Augustine even
went as far to say
Six is a number perfect in itself, and not because god created
all things in 6 days; rather the converse is true. God created
all things in 6 days becaus
e the number is perfect.
This he wrote in the City of God (cited in Ellis, 2004).
Though the Pythagoreans were interested in the occult properties of Perfect Numbers, they
did little of mathematical significance with them. It was around 300BC, when Eucli
d wrote
his
Elements
that the first real result was made. Although Euclid concentrated on Geometry,
many number theory results can be found in his text (Burton, 1980). We shall consider
Euclid’s result in a moment, but first, lets define Perfect Numbers mo
re properly.
There are numerous ways to define Perfect Numbers, the early definitions being given in
terms of
aliquot parts
. This author defines Perfect Numbers as:
A Perfect Number n, is a positive integer
which is equal to the sum of its factors,
exclud
ing n itself.
However, we can define Perfect Numbers in terms of the
restricted divisor function
s
(
n
),
which is the sum of the proper factors of
n
. Thus, if
n
is a Perfect Number
n
=
s
(
n
)
Alternatively, we can use the divisor function
σ
(
n
), which is the
sum of all the factors of
n
.
So, if
n
is perfect, we have
n
=
s
(
n
) =
σ
(
n
)
–
n
σ
(
n
) = 2
n
This latter definition is more widely used, and so will be the convention for this text. Before
continuing, we shall state a lemma concerning the sigma notation:
Le
mma 1
σ(
nm
) = σ(
n
)σ(
m
) (multiplicative) if and only if
n
and
m
are relatively prime
Proof
: We shall not prove this, as it is slightly involved. A proof can be found in Burton
(1980).
Tony Skyner
Perfect Numbers
4
/
30
Returning to Euclid’s result. The result of interest is
Proposition I
X.36 of
Elements
(Dickson,
1952, cited in
Weisstein, 2004), which is quoted as
If as many numbers as we please beginning from a unit be
set out continuously in double proportion, until the sum of
all becomes a prime, and if the sum multiplied into the las
t
make some number, the product will be perfect.
Put simply, if 1 + 2 + 4 + 8 + … +
k
=
p
is prime, then
p
.
k
is a Perfect Number. We can use
the fact that
1 + 2 + 4 + … + 2
k

1
= 2
k
–
1
to rewrite Euclid’s result in a modern form:
Lemma 2
2
k

1
and 2
k
–
1
are relatively prime
Proof
:
The only factors 2
k

1
are multiples of 2, so if 2
k

1
and 2
k
–
1 are not relatively prime,
then 2
k
–
1 must be divisible by some multiple of 2. But then 2
k
–
1 would be divisible by 2,
which is a contradiction as 2
k
–
1 is clea
rly odd.
Proposition 3
If 2
k
–
1 is prime for some integer
k
> 1, then 2
k

1
(2
k
–
1) is perfect.
Proof
:
Cited in Cadwell (2004).
Suppose 2
r
–
1 is prime. From Lemma 2 we have hcf(2
r
–
1, 2
r

1
) = 1, so that 2
r
–
1
and 2
r

1
are relatively prime. So, by the multipli
catively of σ (see lemma 1 above), we
have
which is the definition of a Perfect number.
It should be noted at this point that the Greeks knew of only 4 Perfect Numbers:
6, 28, 496, 8128
The work by Euclid remained the only sign
ificant study of perfect numbers for some time,
until around 100AD when Nicomachus of Geras wrote
Introductio Arithmetica
. In this text,
he divided numbers into three groups:
Deficient numbers: sum of proper factors is less than the number
Abundant numbers
: sum of proper factors is greater than the number
Perfect numbers: sum of proper factors is equal to the number
He also presented 5 conjunctures, all of which he left unproven, and they are:
1)
The
n

th perfect number has
n
digits
2)
All perfect numbers end in
6 and 8 alternately
3)
All perfect numbers are even
4)
Euclid’s algorithm generates ALL perfect numbers
5)
There are infinitely many perfect numbers
Tony Skyner
Perfect Numbers
5
/
30
Nicomachus made no attempt to prove these conjectures, and it seems that he made them with
only Euclids algorit
hm and the 4 known perfect numbers (Ellis, 2004). The first conjecture is
readily disproved, by considering the 5
th
perfect number:
2
12
(2
13
–
1) = 33550336
and the second is disproved by considering the next perfect number:
2
16
(2
17
–
1) =
8589869056
whic
h also ends in 6. However, we shall salvage something from this conjecture: we shall
show that all even perfect numbers end in either 6 or 8 (see proposition 7).
As for the other 3 of Nicomachus’ conjectures, we shall show that Euclid’s algorithm
generate
s all even perfect numbers (see theorem 4). However, we do not know if there are any
odd perfect numbers (none have been found, and therefore it seems highly unlikely that there
are any). Similarly, Nicomachus’ 5
th
conjecture also remains unanswered.
It i
s slightly worrying that, even though these conjectures were unproven (and, as will be
seen, mostly false), they were taken as truth for over 1500 years. No real progress was made,
until 1690, when Fermat announced the discovery of one of the greatest theo
rems in Number
Theory, what is now known as
Fermat’s Little Theorem
(O’Connor & Robertson, 2004). With
this theorem, Fermat was able to make a lot of progress into verifying perfect numbers.
At this point, efforts into searching for perfect numbers had sh
ifted, when Euler proved the
converse of Euclid’s theorem (see theorem 4), and so the search was on for values of
n
such
that 2
n
–
1 is prime. Numbers of this form became known as Mersenne numbers, and we shall
discuss them later. For now, many results con
cerning perfect numbers were discovered (many
of them by Euler), and so now we shall study these in the following section.
Tony Skyner
Perfect Numbers
6
/
30
1.2
Perfect Number Results
As was mentioned earlier, Euclid produced a theorem that gave the means of finding even
perfect numbers.
Below is a theorem from Euler (cited in Burton, 1980) that states that all
perfect numbers are of the form stated by Euclid.
Theorem 4
n
= (2
r
–
1)2
r

1
is an even perfect number if and only if 2
r
–
1 is prime.
Proof
:
Adapted from Burton (1980).
We have
already proven the
only if
part in proposition 3.
Now suppose that
n
is an
even
perfect number. Then
n
is of the form
n
= 2
r

1
m
where, in this context,
m
= 2
r
–
1. As
n
is perfect
σ(
n
) = σ(2
r

1
m
) = 2
n
From lemma 2 above, and the multiplicatively of σ, we have
σ(2
r

1
m
) = σ(2
r

1
) σ(
m
) = (2
r
–
1) σ(
m
)
So, as σ(
n
) = 2
n
as
n
is perfect, we have
(2
r
–
1) σ(
m
) = 2
n
= 2
r
(2
r
–
1)
σ(
m
) = 2
r
= (2
r
–
1) + 1
Thus, σ(
m
) is the sum of
m
a
nd 1 only, which means that these are the only factors of
m
, so, by the definition of primality,
m
must be prime.
We now have a definite means of finding perfect numbers. We simply have to determine
when 2
r
–
1 is prime, and then we automatically have a
perfect number. The next lemma
limits the choice of
r
.
Lemma 5
If
a
k
–
1 is prime, where
a
> 0 and
k
≥ 2, then
a
= 2 and
k
is also prime.
Proof
:
Cited in Burton (1980).
It is well known that
a
k
–
1 = (
a
–
1)(
a
k

1
+
a
k

2
+ … +
a
+ 1)
As
a
> 0, we have
a
k

1
+
a
k

2
+ … +
a
+ 1 ≥
a
+ 1 > 1
Thus, as
a
k
–
1 is prime, and the second factor is greater than 1, we must have
a
–
1 = 1
a
= 2
Now, if
k
is composite and
k
=
rs
where 1<
r
and 1 <
s
, then
a
k
–
1 = (
a
r
)
s
–
1 = (
a
r
–
1)(
a
r
(
s

1)
+
a
r
(
s

2)
+ … +
a
r
+ 1)
But, as
r
,
s
> 1 and
a
= 2 from above, both factors are > 1, which is a contradiction to
the primality of
a
k
–
1, so by contradiction, we must have
k
prime.
So we now know that Mersenne numbers (numbers of the form 2
n
–
1) are prime only if the
i
ndex is prime. However, we know that this is not always the case as, for example
2
11
–
1 =2047 = 23.89
Tony Skyner
Perfect Numbers
7
/
30
The following Lemmas and Propositions quite interesting.
Lemma 6
16
t
≡ 6 mod(10) for all
t
ℕ
.
Proof
:
We shall proceed by induction. Clearly, for
t
= 1 we have
16
1
= 16 ≡ 6 mod(10)
Now suppose that the assertion is true for
t
=
k
, that is
16
k
≡ 6 mod(10)
Then we must show that 16
k
+1
≡ 6 mod(10), so
So, by induction, the assertion is true.
Proposition 7
An even perfect
number
n
ends in the digit 6 or the digits 28.
Proof
:
Partially cited in Barton (1980).
We are required to prove that
n
≡ 6 mod(10) or
n
≡ 28 mod(100)
As
n
is an even perfect number, we know it has the form
2
p

1
(2
p
–
1)
where, from Lemma 5,
p
is p
rime. Clearly, if
p
= 2,
n
= 6 and the assertion holds. We
can thus confine the proof to
p
> 2, and so we shall continue in two parts, according as
p
takes the forms 4
m
+ 1 or 4
m
+ 3.
For
p
= 4
m
+ 1, we have
n
= 2
4
m
(2
4
m
+1
–
1) = 2
8
m
+1
–
2
4
m
= 2∙16
2
m
–
16
m
Lemma 6 gives 16
t
≡ 6 mod(10) for all
t
ℕ
, thus
n
≡ 2∙6
–
6 ≡ 6 mod(10)
Now, if
p
= 4
m
+ 3, we can note that
2
p

1
= 2
4
m
+2
= 4∙16
m
≡ 4∙6 ≡ 4 mod(10)
Moreover, for
p
> 2, we have 42
p

1
and so we have that the number formed by the last
two digits of
2
p

1
is divisible is divisible by 4, and the last digits is 4. So, the
possibilities are:
2
p

1
= 4, 24, 44, 64, or 84 (mod(100))
But this implies
2
p
–
1 = 2∙2
p

1
–
1 ≡ 7, 46, 87, 27, or 67 (mod(100))
Thus, we have
n
= 2
k

1
(2
k
–
1) = 4∙7, 24∙47, 44∙87,
64∙27, or 84∙67 (mod(100))
Tony Skyner
Perfect Numbers
8
/
30
To complete the proof, we must now show that each of the above is congruent to 28
modulo 100. The first (4∙7 = 28) is clearly true.
Now, working over the integers mod(100), we have
The remaining thr
ee can be verified in a similar manner, and is left to the reader.
Proposition 8
All even perfect numbers are triangular numbers.
Proof
:
As
n
is an even perfect number, we have
n
= 2
p

1
(2
p
–
1)
If
n
is also a triangular number, then it must be of the
form
n
= ½
k
(
k
–
1)
The proof is completed by simply setting
k
= 2
p
Then
½
k
= 2
p

1
and
k
–
1 = 2
p
–
1
Lemma 9
Let
n
be a positive integer, and let
s
(
n
) be the sum of the digits of
n
. Then, working in
the integers mod(9),
s
(
n
) =
n
.
Proof
:
Conside
r the digit representation of
n
:
n
=
a
1
a
2
a
3
…
a
r
Then
s
(
n
) =
a
1
+
a
2
+ … +
a
r
To calculate
n
mod(9), consider the following:
n
mod(9) =
n
–
9
k
=
n
–
10
k
+
k
for some
k
. Now set
k
=
a
1
a
2
…
a
r

1
(
n
with it’s last digit removed), then
n
mod(9) = (
a
1
a
2
a
3
…
a
r

1
a
r
)
–
(
a
1
a
2
a
3
…
a
r

1
0) +
a
1
a
2
…
a
r

1
=
a
r
+
a
1
a
2
…
a
r

1
Continuing this process, we end up with
n
mod(9) =
a
r
+
a
r

1
+ … +
a
1
=
s
(
n
)
As required
Tony Skyner
Perfect Numbers
9
/
30
Theorem 10
With the exception of 6, if the digits of an even perfect number
n
are summed, and
then the di
gits of that number summed and so on until a single digit is obtained, then
that digit is 1.
Proof
:
Adapted from Cadwell (2004).
From the above lemma, we only need to show that all even perfect numbers are
congruent to 1 mod(9). Consider the group of
integers
Z
/9
Z
. It is trivial to show that 2
has order 6 in this group, that is
2
6
≡ 1 mod(9)
So, we only need to consider the numbers 2
r

1
(2
r
–
1) for
r
= 1, 2, 3, 4, and 5. We have
already excluded 6, and clearly no prime number is congruent to 4 mod(6), thus it
remains to show that the numbers
2
0
(2
1
–
1), 2
2
(2
3
–
1), 2
4
(2
5
–
1)
ar
e all congruent to 1 mod(9). This is left to the reader to verify
As an example of the above theorem, consider the perfect number
496
4+9+6 = 19
1+9 = 10
1+ 0 = 1
1.3
Other Forms of Perfect Numbers
1.3.1
Odd Perfect Numbers
One of the greatest unsolved pr
oblems of classical mathematics is the answer to a very simple
question: are there any odd perfect numbers? At the moment, the answer is “we don’t know,
we haven’t found any yet”, and at the same time we cannot prove that there aren’t any. In
1908, Turcani
nov (cited in Burton, 1980) showed that if any did exis
t, then thy must have at
least 5 distinct primes, and would be more than 2∙10
6
. Modern computers have shown that, if
fact, if any exists, they would have to be greater than a
googolplex
(that is, 10
100
).
Although no example of an odd prime has been found,
there has been a fair amount of theory
about them (though most beyond the scope of this text). The following theorem from Euler
was one of the first developments on the issue.
Theorem 11
If
n
is an odd prime number, then
where
the
p
,
q
1
, …
q
r
are distinct odd primes, and
p
≡ α ≡ 1 mod(4).
Proof
:
Cited in Barton (1980).
Let
be the prime factorisation of
n
. Since
n
is perfect, we have
As
n
is an odd integer, either
n
≡ 1 mod(4) or
n
≡ 3 mod(4). In either case
2
n
≡ 2 mod(4)
T
hus σ(
n
) = 2
n
is divisible by 2, but not by 4. This implies that one of the factors
above, say σ(
p
α
), must be even (but not divisible by 4), while the remaining
are odd integers.
Tony Skyner
Perfect Numbers
10
/
30
For each
q
i
, there are two possibilities:
q
i
≡ 1 mo
d(4) and
q
i
≡ 3 mod(4)
If
q
i
≡ 3 ≡

1 mod(4), we have
Since σ(
p
α
) is divisible by 2, but not 4, we have
σ(
p
α
) ≡ 2 mod(4)
This tells us that
p
≢
3 mod(4), because if
p
≡ 3 mod(4), then
But we know
that neither is true. Thus we must have
p
≡ 1 mod(4).
Now,
implies that 4 divides
, which is not possible, thus, if
q
i
≡ 3 mod(4), then it’s exponent
k
i
is an even integer. Should
q
i
≡ 1 mod(4), then
As
, this gives
k
i
≡ 0 or 2 mod(4). In either case, this gives
k
i
is
even for all
i
. Similarly, the condition σ(
p
α
) ≡ 2 mod(4) forces α ≡ 1 mod(4). The
proof is completed by setting
k
i
= 2
β
i
for some positive inte
gers
β
i
.
In 1888 Syvester proved that an odd perfect number must have at least 4 distinct prime
factors. This result has improved to 8 distinct prime factors, and 29 non

distinct prime factors,
and the number would have to be more than 300 digits long,
and it smallest prime factor must
be greater than 10
6
(cited in Ellis, 2004)
It is very curious how so much work, and so many theorems and
proofs
, have been created
concerning a set of numbers that do not appear to exist at all. It is ironic the above the
orem,
along with many others, place conditions on the existence of these numbers, and there is a
very good chance that in the near future, someone will produce a proof that they do not exist
at all!
Tony Skyner
Perfect Numbers
11
/
30
1.3.2
Multiply Perfect Numbers
A Multiply Perfect Numb
er (or Pluperfect Number) is a number such that the sum of it’s
proper factors is an integer multiple of itself. In terms of the sigma notation, multiply perfect
numbers are defined as
σ
(
n
) =
kn
where
k
is called the abundency (or multiplicity) of
n
. We e
ither say that
n
is a multiply
perfect number with abundancy
k
, or that
n
is a
k

fold pluperfect number (Flammenkamp,
2004).
So, perfect numbers are 2

fold pluperfect numbers by definition. For example, consider the
number 120, then
σ(120) = σ(2
3
.3.5) = σ
(2
3
) σ(3) σ(5) = (2
4
–
1).4.6 = 15.24 = 360 = 3.120
thus, 120 is a 3

fold pluperfect number (or is a multiply perfect number, abundancy 3).
There are many other “types” of perfect numbers; some examples are listed below:
Quasiperfect numbers
These are d
efined as
σ(
n
) = 2
n
+ 1
Any number, whose sum of its proper factors is greater than itself, is known as an
abundant number. Thus, quasiperfect numbers are the least abundant numbers.
However, none are known to exists (if they do they must be greater than
10
35
)
(Weisstein, 2004)
Almost perfect numbers
These are defined as
σ(
n
) = 2
n
–
1
They are also called
slightly defective numbers
, and the only ones known to exist are
the powers of 2, i.e. 2, 4, 8, 16, 32, … (Weisstein, 2004)
Hyperperfect numbers
These
are defined as
n
= 1 +
k
(σ(
n
)
–
n
–
1)
Note that setting
k
= 1 gives the usual definition of a perfect number. Many of these
are known, and some theory is available, but we shall not consider them further (for
more information, see Weisstein
–
for furthe
r references) (Weisstein, 2004).
Superperfect numbers
These are defined as
σ
2
(
n
) = σ(σ(
n
)) = 2
n
The only even superperfect numbers are 2
p

1
where 2
p
–
1 is (a Mersenne) prime. No
odd superperfect numbers are known (Weisstein, 2004).
Tony Skyner
Perfect Numbers
12
/
30
Chapter 2: Mersenne
Primes
2.1
Historical Interests
The story of Mersenne Numbers starts in the 16
th
Century, with the French Monk, Father
Marin Mersenne (1588
–
1648). Mersenne had gained an interest in the numbers of the form
2
n
–
1 (mainly from Fermat’s new tools, like his
Little Theorem), and in 1644 produced
Cogitata Physica

Mathematica
, in which Mersenne stated that 2
p
–
1 is prime for the values
of
p
2, 3, 5, 7, 13, 17, 19, 31, 67, 127, 257
and composite for all other values of
p
< 257. It was clear to Mersennes peers t
hat he could
not have possibly tested all these values, and as it is, his assertion was incorrect (cited in Ellis,
2004).
Some of the numbers had already been determined for primality. In 1536, Huddrichus Regius
(a prolific mathematician who has almost b
een forgotten in modern times) produced in his
Utruisque Arithmetices
the following factorisation:
2
11
–
1 = 2047 = 23∙89
This may seem a small accomplishment, but it must be remembered that this calculation
would probably have been done in Roman Numerals
(with the aid of an abacus), as Arabic
numbers had not yet won over (Burton, 1980). Regius also verified that
p
= 13 produced the
next
Mersenne Prime
(although Mersennes name had not yet been ascribed to them),
producing the 5
th
perfect number:
2
12
(2
13
–
1) = 33, 550, 336
At this time, the only means for determining the primality of a number was to try and divide
through by primes smaller than it’s square root. But very few primes (relatively speaking)
were known, and so in 1603, Pietro Cataldi produced a
table of primes less than 5150, and
determined that 2
17
–
1 is prime (cited in Ellis, 2004).
Further work by Euler, Fermat, and other great mathematicians of the time, produced a
number of works on the subject, but little progress towards Mersennes conju
ncture was made.
The 19
th
Century saw some more interesting developments, though some mathematicians
were sceptical. In 1811, after proving that 2
31
–
1 is prime, Barlow (1980, in his
Theory of
Numbers
) concluded by saying that his prime “
… is the greatest
that ever will be discovered;
for as they are merely curious, without being useful, it is not likely that any person will ever
attempt to find one beyond it
” (cited in Burton, 1980). Clearly Barlow seriously
underestimated the human curiosity, which will
always strive to discover greater finds,
regardless of the cost or whether the findings have any practical value. However, in this case,
Barlow was even further from the truth, as many important applications of Mersenne Primes
exists, especially in Coding
Theory, and Internet Banking, where the large primes are used in
security tests.
The most important development came later that Century, when Edward Lucas determined
that 2
127
–
1 is prime without actually computing the number. This was the largest known
for
the next 75 years. In 1947, an adaptation of Lucas’methods (what is known as the Lucas

Lehmar Test, see §3.2.2) was used along with high

speed computers to finally check all of
Mersennes predictions. All 55 primes less than 257 were tested, and it was
found that
Mersenne had made 5 errors: he had included 2
67
–
1 and 2
257
–
1, and excluded 2
61
–
1, 2
89
–
1 and 2
107
–
1 (Burton, 1980).
Tony Skyner
Perfect Numbers
13
/
30
Today, the search for large Mersenne primes goes on, the last decade mainly dominated by
GIMPS, the Great Internet M
ersenne Prime Search (more on them later), and the search for
answer to some of the many questions surrounding Mersenne primes, like, ‘is there an infinite
or finite number of them?’ It was conjuncture that double Mersenne primes (i.e. a Mersenne
prime who
se index is a Mersenne Prime) are always prime, but alas, in 1953, with the aid of
high speed computers, it was found that
is composite (Ellis, 2004).
The search for Mersennce Primes (and thus perfect numbers) has led to some of th
e most
important developments in mathematics, not only in Number Theory, but in other areas such
as computational mathematics, calculus and statistics. Fermat discovered his Little Theorem
as a result of searching for Mersenne Primes.
Tony Skyner
Perfect Numbers
14
/
30
2.2
Mersenne Results
Th
e search for Mersenne Primes (and thus perfect numbers) is not at all trivial. The first step
is to reduce the list of possible prime indices. We proceed with the following three theorems
that lead to a corollary that is paramount in the search. We shall d
enote a Mersenne number
2
n
–
1 by M
n
.
Theorem 12
If
p
> 2 is prime, then
p
divides one of
or
, but not both.
Proof
:
Fermat’s Little Theorem gives
2
p

1
–
1 ≡ 0 mod
p
so
p
divides 2
p

1
–
1, but
So
p
divide at least one of the two factors. As the factors differ by 2, and
p
> 2,
p
cannot divide both.
This theorem does not tell us much about Mersenne primes, but it is a good mo
tivation for the
next theorem, which is proved in a very similar manner.
Theorem 13
If
p
> 2 and
q
= 2
p
+ 1 are prime, then either
q
M
p
or
q
(M
p
+ 2), but not both.
Proof
:
Cited in Barton (1980).
Fermat’s Little Theorem gives
2
q

1
–
1 ≡ 0 mod
q
Factor
ising the LHS gives
which is the same as saying
M
p
(M
p
+ 2) ≡ 0 mod
q
This gives
q
M
p
or
q
(M
p
+ 2) but not both, for the same reason as in theorem 11.
This could be used to verify if M
p
is composite, however the amount of wor
k to determine
whether
q
divided M
p
or M
p
+ 2 makes this theorem a little difficult to use. This next theorem
determines when
q
divides M
p
and M
p
+ 2.
Tony Skyner
Perfect Numbers
15
/
30
Theorem 14
If
q
= 2
n
+ 1 is prime (
n
> 0), then
1)
q
M
n
provided that
q
≡
1 mod 8
2)
q
(M
n
+ 2) provi
ded that
q
≡
3 mod 8
Proof
:
The proof shall not be presented here, as it requires Legendre Symbols, and follows
from the previous theorem. A proof can be found in Barton (1980).
Note that the two possibilities in the above theorem exhaust all possibili
ties for
q
(i.e. all odd
values
q
could take). Now we know when
q
divides M
p
. The following corollary condenses
the above theorems into an easy test.
Corollary 15
If
p
≡ 3 mod(4) and
q
= 2
p
+ 1 are both odd primes, then
q
M
p
.
Proof
:
Cited in Barton (198
0)
An odd prime is either of the form 4
k
+ 1 or 4
k
+ 3. So
p
= 4
k
+ 3
q
= 8
k
+ 7
q
≡ 7 ≡

1 mod 8
and
p
= 4
k
+ 1
q
= 8
k
+ 3
q
≡ 3 mod 8
From the previous theorem, both cases result in
q
M
p
.
This can be easily applied, and in fact removes a la
rge number of composite Mersenne
numbers. For example, if
p
= 11 then
q
= 23 (which is prime). But 23
–
3∙8 = 23
–
24 =

1, so
that 23 ≡

1 mod 8. Thus, by Corollary 15, 23 divides 2
11
–
1.
We now have a list of “possible” Mersenne Primes. To verify if
a Mersenne number is indeed
prime, it is sometimes easiest (especially with small numbers) to exhaust possible prime
factors. The following 2 theorems show that any prime factor of a Mersenne Number is of a
precise form (an example will follow to show how
this can be used).
Theorem 16
If
p
is an odd prime, then any prime divisor of M
p
is of the form 2
kp
+ 1 (or is
equivalent to 1 mod (2
p
)).
Proof
:
Adapted from Barton (1980)
Let
q
be any prime divisor of M
p
, and consider the ring of integers mod
q
(it can
be
shown that this is a field, and is denoted by
Z
/
pZ
). As
q
is a divisor of 2
p
–
1, we have
that
2
p
≡ 1
We need to show that
p
is the smallest integer such that this holds (that is, to show that
2 has order
p
as an element of the group of integers mod
q
under multiplication). So,
suppose there exists a smallest integer
k
such that
2
k
≡ 1 mod
q
As a consequence of Lagrange’s Theorem, we have
k

p
. Now, we cannot have
k
= 1,
otherwise
2
1
≡ 1
1 ≡ 0 mod
q
q
1
which is an impossible situation. From th
is, and the primality of
p
, we must have
k
=
p
.
Tony Skyner
Perfect Numbers
16
/
30
From Fermat’s Little Theorem, we have
2
q

1
≡ 1 mod
q
and so, again Lagrange’s Theorem, we have
k

q

1. As
k
=
p
, this gives
p

q

1, or
q
–
1 =
pt
q
=
pt
+ 1
Finally, we note that if
t
were odd, then
pt
+ 1 would be even. But
q
must be an odd
prime (as
p
> 2, because we know that M
2
is prime), so
t
must be even. That is
q
= 2
kp
+ 1
for some integer
k
.
Theorem 17
If
p
is an odd prime, then any prime divisor
q
of M
p
is of the form
q
≡
1 mod 8
Proof
:
Cited in Barton (1980)
We have seen a special case of this in theorem 13. Suppose that
q
is odd, so
q
= 2
n
+ 1, and is a prime divisor of M
p
. Set
then
a
2
–
2 = 2
p
+1
–
2 = 2M
p
≡ 0 mod
q
Now, raising both sides of the congruence
to the n

th power gives
a
q

1
=
a
2
n
≡ 2
n
mod
q
As
q
is an odd integer, and
a
is even, we have
hcf(
a
,
q
) = 1
a
q

1
≡ 1 mod
q
2
n
≡ 1 mod
q
q
M
p
This can now be compared to theorem 13, which gives us
q
≡
1 mod 8.
To demonstrate this, consider M
21
=
2
21
–
1 = 2097151. To determine whether this is prime,
we could check for prime factors less than its square root (which is <
1449). The only primes
that satisfy the previous two results, and are less than 1449 are:
127 337 463 631 673 967 1009 130
3
In fact, direct computation shows that both 127 and 337 are factors of 2
21
–
1, but the rest are
not. Thus, 2
21
–
1 is not a Mersenne prime.
One of the many unanswered questions concerning Mersenne numbers is whether they are
square

free
, that is, whet
her they have any factors which are squares (i.e. is M
q
divisible by
p
2
, for some prime
p
).
If 2
p

1
–
1 is divisible by
p
2
then
p
is called a Wieferich prime. The following proposition
shows that if a Mersenne number is divisible by some prime squared, th
en that prime is a
Wieferich prime
Tony Skyner
Perfect Numbers
17
/
30
Theorem 18
If
p
> 2 (prime) divides 2
q
–
1 for some
q
> 2, then
p
is a Wieferich prime.
Proof
:
Cited in Cadwell (2004)
From Theorem 16, we have that
p
= 2
kq
+ 1 for some
k
. Thus, as
p
divides 2
q
–
1 we
have:
Raising the congruence to the 2
k

th power gives 2
p

1
1 mod (
p
2
), so that
p
is a
Wieferich prime, as required.
It is not known whether the set of Wieferich primes is finite or infinite, but Wieferich primes
are very rare: there are o
nly two less than 3×10
12
, and they are
1093 and 3511
(Hardy & Wright, 2002). Because of this, it is fairly reasonable to consider Mersenne
numbers to be square free.
The following proposition is an adaptation of a proof from Hardy & Wright (2002).
Pro
position 19
1093 is a Wieferich prime.
Proof
:
Set
p
= 1093. For
p
to be a Wieferich prime, we must have
p
2
divides 2
p

1
–
1. This is
the same as saying
2
p

1
–
1 ≡ 0 mod
p
2
So, working over the integers mod 1093
2
, we have
3
7
= 2187 = 2
p
+ 1
3
14
= (2
p
+ 1)
2
= 4
p
2
+ 4
p
+ 1 ≡ 4
p
+ 1
and
2
14
= 16384 = 15
p
–
11
2
28
= 225
p
2
–
330
p
+ 121 ≡

330
p
+ 121
so that
3
2
.2
28
≡

2970
p
+ 1089 =

2969
p
–
4 ≡

1876
p
–
4
and so
3
2
.2
26
= (

1876
p
–
4)/4 =

469
p
–
1
Hence, by the binomial theorem
3
14
.2
182
≡

(469
p
+ 1)
7
≡

3283
p
–
1 ≡

4
p
–
1 ≡

3
14
from the working above. Thus we have
2
182
≡

1
2
1092
≡ 1mod
p
2
2
p

1
–
1 ≡ 0mod
p
2
ٱ
Tony Skyner
Perfect Numbers
18
/
30
Chapter 3: Primality Testing
3.1
Introduction
The search for Mersenne primes may seem of very little importance, but (as ment
ioned
earlier) large primes are of great importance, as well as of major interest to the mathematical
community. The efforts employed in their discovery have lead to some of the major
developments in mathematics (e.g. Fermat’s Little Theorem). So why do we
need large
primes? With the modern age of computers, systems of encoding data need to be incredible
difficult to “break”, but fairly easy to use. That’s where primes come in. Simple put, if we
multiply two very large prime numbers together, and then trans
mit the result, then there are
only two possible factors for the decoder to find (so no ambiguities). But if a hacker finds this
result, they will find it very difficult to randomly “guess” the factorisation. However, as
computers get more advanced, the po
ssibility of someone doing this increases. The only
solution is to use larger primes.
As we shall see in the next section, finding Mersenne primes is not easy. However, the task of
finding them has been taken up by GIMPS (the
G
reat
I
nternet
M
ersenne
P
rime
S
earch). In
1995, the programmer George Woltman started to gather up all the databases of Mersenne
prime data, and wrote an optimised version of the Lucas

Lehmar test (see §3.2.2). He was
motivated by Slowinski, who works for Cray computers. He wrote a co
mputer program
(based on the Lucus

Lehmar Test), and set the computers in all the Cray Labs to run the test
in their spare time (Cadwell, 2004).
In 1997, Scott Kurowski set up PrimeNet, which helped distribute Woltman’s software
(which is completely free)
to as many people as possible. So, with a handful of experts, and
thousands upon thousands of amateurs (all running the program in their computers spare time,
and sending the data to GIMPS via the internet
–
the process complete automated), the search
for
Mersenne Primes has entered an entirely new level (Cadwell, 2004).
GIMPS is currently the world record holder for the largest prime, which Josh Findley
discovered on 15
th
May 2004. The number he discovered is
2
24 036 583
–
1
This number has 7,235,733 di
gits, and is the 41
st
Mersenne prime. GIMPS uses a highly
optimised program, using some of what we have already seen, the Lucas

Lehmar test below
and Fast Fourier Transforms (FFT). However, we shall now consider some simpler tests for
finding Mersenne Prim
es.
Tony Skyner
Perfect Numbers
19
/
30
3.2
Common Tests for Mersenne Primes
3.2.1
Using Fermat’s Little Theorem
Fermat’s Little Theorem is a powerful Number Theory tool, and can be used to an extent to
test for primes. As a reminder, his theorem states:
Theorem 20
If
a
and
p
are r
elatively prime, then
a
p

1
≡ 1 mod(
p
)
So, if we have some number
n
and we want to test for primality, we could just pick a number
relatively prime to
n
, raise it to the
n

1 power, and see if it is congruent to 1 mod(
n
). If it isn’t
then
n
is definitely no
t prime (as the above is true for all
p
and
a
). However, if it is, then we
would need to check another number. Clearly we would have to check 2, 3, … (
n

1). If the
congruence holds for all these, then
n
must be prime!
However, there is a class of composit
e numbers that satisfy Fermat’s Little Theorem for all
integers
a
. These are called
Carmichael numbers
. Though they are fairly rare (the first few are
561, 1105, 1729, 2465), it has been proven that there is an infinite many of them, and so
Fermat’s Little
Theorem is not completely reliable (Cadwell, 2004). However, we could use
Fermat’s Little Theorem to determine whether a given Mersenne is
probably
prime.
An attempt at writing a Maple Procedure for using Fermat’s Little Theorem was made, but
with little
success. The procedure produced was only effective at testing primes smaller than
2
31
–
1; clearly this is not very good (although, the procedure may not have been written in the
most optimal way).
The next method we shall look at tells us
exactly
if the
given Mersenne number is prime or
not.
3.2.2
Lucas

Lehmar Test
One of the most useful and used test for determining the primality of Mersenne numbers is the
Lucas

Lemar Test. This test tells absolutely whether a given Mersenne number is prime or
not. Most mod
ern tests use adaptations of this theorem. We shall consider this theorem and
it’s proof (Lucas

Lehmar, 1930, cited in Caldwell, 2004), but first we shall prove a short
lemma:
Lemma 21
If
s
n
=
s
n

1
2
–
2 and
s
1
= 4, then
Proof
:
We
shall prove by induction. Let
and
, then
i)
Let
n
= 1, then
which is true.
ii)
Now assume that the lemma is true for
n
=
k
, i.e.
Tony Skyner
Perfect Numbers
20
/
30
We shall show that
We have that
s
k
+1
=
s
k
2
–
2, so
as
and
. So by induction,
the lemma is true.
ٱ
Theorem 22
Let
p
be an odd prime, then
M
p
(the
p
th
Mersenne) is prime if and only if
s
(
p
–
1)
≡ 0
mod
M
p
, where
s
1
= 4 and
s
n
=
s
n

1
2
–
2
Proof
:
Cited in Cadwell (2004)
We shall prove sufficiency only. Let
and
, then from the above
lemma, we have
Thus,
M
p
divides
s
p

1
means that the exists an integer
R
such that
or, multiplying through by
and subtracting 1, we have
(1)
We shall now prove by contradiction. Suppose
M
p
is composite, and choose
q
, one of
M
p
’s prime factors which is less than
. Now consider the group
This is the field of integers mod
q
with
3 a
djoined, or all the numbers of the form
which are invertible. Note that
G
has at most
q
2
–
1 elements. Now,
as
M
p
has a factor
q
, looking at
w
mod
q
makes (1) become
Thus
w
is an element of
G
of order 2
p
. S
ince the order of an element of a group is at
most the order of the group itself, we have
2
p
≤
q
2
–
1 <
M
p
= 2
p
–
1
which is a contradiction, thus proving the theorem.
Tony Skyner
Perfect Numbers
21
/
30
This test has many great advantages, as it is easily programmed into appropriate software
(such as Maple, see §3.4). To demonstrate its use, consider M
5
(= 31). The first 4
values in the
iteration are
S
1
= 4
S
2
= 4
2
–
2 = 14
S
3
= 14
2
–
2 = 194
S
4
= 194
2
–
2 = 37634 = 31∙1214
So, as S
4
is divisible by 31, 31 is prime (which, of course, we already knew). This example
also demonstrates the tests main (and maybe even only) weak
ness: the huge values that are
introduced. In §3.4, we shall see how this procedure breaks down for larger
p
.
3.3
Formula For Primes
In 1976, the mathematicians James Jones, Diahachiro Sato, Hideo Wada and Douglas Wein
published the paper
Diophantine Represe
ntation of the Set of Prime Numbers
, in which they
produced a formula that generates a set of numbers that is identical to the set of prime
numbers (cited in Bowyer, 2004). Their work was based on the work done by C.P. Willans,
who published a paper in 196
4 entitled “On Formulae for the Nth Prime Number”. In this
paper he produced the following theorem (adapted for the purposes of this text).
Theorem 23
For all positive integers
x
, we define the function
f
as
where
⌊⌋
is the usual floor operator. If
f
(
x
) = 1, then
x
is prime, and if
f
(
x
) = 0 then
x
is
composite.
Proof
:
We shall not prove this. A proof can be found in the above

mentioned paper, found in
the
Mathematical Gazzette
Volume 48, pages 413 to 415.
From thi
s result, Willan was able to establish the following formula for the
n
th
prime number:
In the next section, we shall see how the above test, along with others, performs at
determining if a Mersenne number is prime, or not.
Tony Skyner
Perfect Numbers
22
/
30
3.4
Maple Procedures For Testing Mersenne Primes
3.4.1
Lucas

Lehmar Test
We shall now look at the Lucas

Lehmer Test, and develop a modified version, which will be
more suited to programming in Maple. Let us restate the original theorem
Let
p
be an odd prime
, then
M
p
(the
p
th
Mersenne) is prime if and only
if
s
(
p
–
1)
≡ 0 mod
M
p
, where
s
1
= 4 and
s
n
=
s
n

1
2
–
2
This can easily be programmed into Maple as a
procedure
, though for larger
p
, the huge
numbers involved pose problems. To tackle this, we shall make
a small alteration to the
theorem above, using the following lemma:
Lemma 24
Let
f
(
X
) be a polynomial of degree
n
,
p
a prime number, and
s
a positive integer,
where
p
does not divide
s
or any of the coefficients of
f
(
X
). Then
f
(
s
) ≡
f
(
s
mod
p
) mod
p
Proo
f
:
We shall prove this for
f
(
X
) a quadratic polynomial
f
(
X
) =
a
1
X
2
+
a
2
X
+
a
3
where
a
1
,
a
2
and
a
3
are integers. The idea is easily extended to the general case.
Let
s
mod
p
=
d
(i.e.
s
≡
d
mod
p
), then
k
such that
s
=
d
+
kp
, so
Now, as
a
1
,
a
2
,
a
3
,
k
are integers, all terms involving
p
are ≡ 0 mod
p
. Also, by
elementary Algebra,
p
does not divide any other terms as
p
does not divide
a
i
i
or
d
,
so
f
(
s
) mod
p
=
a
1
d
2
+
a
2
d
+
a
3
=
f
(
d
)
but
d
=
s
mod
p
, so
f
(
s
) mod
p
=
f
(
s
mod
p
)
f
(
s
) ≡
f
(
s
mod
p
) mod
p
ٱ
In particular, if
s
n
=
f
(
s
n

1
) =
s
n

1
2
–
2
s
n
≡
f
(
s
n

1
mod
p
) mod
p
We can now use this to restate the Lucas

Lehmer Test in the following:
Corollary 25
Let
p
be an odd prime, then
M
p
(the
p

Mersenne) if
s
(
p
–
1)
≡ 0, where
s
1
= 4 and
s
n
= (
s
n

1
2
–
2) mod
M
p
Proof
:
This follows directly from the Lucas

Lehmer Theory (theorem 22), and the above
lemma
ٱ
Tony Skyner
Perfect Numbers
23
/
30
This modified version of the Lucas

Lehmer Test is now more suited for programming, as the
iteration is greatly scaled down
at each step, avoiding such large numbers forming. This will
greatly reduce the runtime required to perform the iteration, as well as reducing the memory
requirements (vital for testing larger primes). For example, to test
M
31
requires over 50
Megabytes,
and takes over 200 seconds when using the original test. However, using the
modified version requires negligible amounts of memory, and is performed almost instantly.
The syntax inserted to Maple to perform this procedure is:
>
LLT:= proc(n)
local i,x,k;
Digits:=2;
x[0]:=4;
for i to n do
x[i]:= (((x[i

1])^2)

2) mod(2^n

1);
for k to 45 do
if 1000*k=i then print(evalf(i/n*100)) else true;
end if;od;od;
if type(x[n

2],poszero)=false then print("LLT Test
complete: Not Prime");
else
print("LLT Test
complete: Prime");
end if;
end;
The third, eighth and ninth lines could be omitted, as they display the percentage of the
process completed after every 1000 iterations. A print screen of a typical output can be found
in the Appendix (§4.1).
The proced
ure was run for all the Mersenne Prime up to
M
44497
using the University of Bristol
School of Mathematics computers, and the time and memory demands were recorded. The
table below summarises the results of this test.
Num †
M
p
†
Digits †
Time (
s
)
Mem (Mb)
27
2
44497
–
=
N
=
ㄳ㌹N
=
㤷㤮㈪
=
㔱㈪
=
㈶
=
O
23209
–
=
N
=
㘹㠷
=
㜳ㄮT
=
㈱O
=
㈵
=
O
21701
–
=
N
=
㘵㌳
=
㔰ㄮR
=
ㄷN
=
㈴
=
O
19937
–
=
N
=
㘰〲
=
㐰ㄮ4
=
ㄵN
=
㈳
=
O
11213
–
=
N
=
㌳㜶
=
㐮N
=
㔲⸱
=
㈲
=
O
9941
–
=
N
=
㈹㤳
=
㜹⸴
=
㐱⸲
=
㈱
=
O
9689
–
=
N
=
㈹ㄷ
=
㜴⸳
=
㌹⸶
=
㈰
=
O
4423
–
=
N
=
ㄳ㌲
=
ㄴ⸶
=
ㄲ⸰
=
ㄹ
=
O
4253
–
=
N
=
ㄲ㠱
=
ㄴ⸲
=
ㄱ⸲
=
ㄸ
=
O
3217
–
=
N
=
㤶9
=
㠮U
=
㠮U
=
ㄷ
=
O
2281
–
=
N
=
㘸S
=
㌮P
=
㘮〰
=
ㄶ
=
O
2203
–
=
N
=
㘶S
=
㌮P
=
㔮㔶
=
ㄵ
=
O
1279
–
=
N
=
㌸P
=
㈮O
=
㈮㠱
=
ㄴ
=
O
607
–
=
N
=
ㄸN
=
㈮O
=
㈮㠱
=
ㄳ
=
O
521
–
=
N
=
ㄵN
=
M
=
M
=
ㄲ
=
O
127
–
=
N
=
㌹
=
M
=
M
=
ㄱ
=
O
107
–
=
N
=
㌳
=
M
=
M
=
=
O
89
–
=
N
=
㈷
=
M
=
M
=
9
=
O
61
–
=
N
=
ㄹ
=
M
=
M
=
U
=
O
31
–
=
N
=
=
M
=
M
=
T
=
O
19
–
=
N
=
S
=
M
=
M
=
Tony Skyner
Perfect Numbers
24
/
30
6
2
17
–
=
N
=
S
=
M
=
M
=
R
=
O
13
–
=
N
=
4
=
M
=
M
=
4
=
O
7
–
=
N
=
P
=
M
=
M
=
P
=
O
5
–
=
N
=
O
=
M
=
M
=
O
=
O
3
–
=
N
=
N
=
M
=
M
=
N
=
O
2
–
=
N
=
N
=
Returned false
Table 1: Results of Primality Testing using the modified Lucas

Lehmar Test († Sloane, cited in
Cadwell, 2004). *Iteration
s terminated at 42% completion due to insufficient resources, and values
given at time of termination.
Note that
M
2
returned false, as
p
must be greater than 2, and that
M
44497
could not be verified,
as the demands on the system were too great. So the pro
cedure is fairly effective, but breaks
down at larger primes. The procedure would also be useless at finding Mersenne primes, as it
would take years to check all possible indexes. We shall consider a more efficient algorithm
in §3.4.3.
3.4.2
Formula for Primes
Next we shall consider the formula for prime numbers discussed in §3.3. The theorem was:
For all positive integers
x
, we define the function
f
as
where
⌊⌋
is the usual floor operator. If
f
(
x
) = 1, then
x
is prime, and if
f
(
x
) = 0
then
x
is composite.
This is also fairly simple to program into Maple, using the following code:
>
FP:=proc(n)
local h,m;
m:=2^n

1;
h:=floor(cos(Pi*(factorial(m

1)+1)/m)^2);
if h=1 then print("FP test complete: Prime") else
print("FP test complete: No
t Prime");
end if;
end;
A print screen of a typical run of this program can be found in the Appendix (§4.2). As in
§3.4.2, this procedure was run and the following data collected:
Num †
M
p
†
Digits †
Time (
s
)
Mem (Mb)
8
2
31
–
=
N
=
=
G
=
G
=
T
=
O
19
–
=
N
=
S
=
㔱R
=
ㄲ㌮N
=
S
=
O
17
–
=
N
=
S
=
㠮U
=
ㄱ⸹
=
R
=
O
13
–
=
N
=
4
=
M
=
M
=
4
=
O
7
–
=
N
=
P
=
M
=
M
=
P
=
O
5
–
=
N
=
O
=
M
=
M
=
O
=
O
3
–
=
N
=
N
=
M
=
M
=
N
=
O
2
–
=
N
=
N
=
M
=
M
=
Table 2: Results of Formula For Primes Test. († Sloane, 2004, sited in Cadwell, 2004). *Test
stopped after 10min
As should be clear from Table 2,
this test is very poor at testing Mersenne Primes. This is
because this test is not specific to Mersenne Primes, but can be used for all primes (whereas
the Lucas

Lehmar Test is for Mersenne Primes only).
Tony Skyner
Perfect Numbers
25
/
30
3.4.3
Conglomerate of Tests
Our final task is to produ
ce an efficient algorithm for finding Mersenne Primes (and thus
Perfect Numbers). We shall need all of the theory we have seen to do this. We shall start by
creating a procedure that uses this number theory to ensure that the index of the Mersenne
number i
s of the correct form. We shall do this in the following order:
First we check that the index is prime (Lemma 5, §2.1)
Then we shall check to see if the index is 2 or 3 (as some of the theorems and test do
not apply for these values).
Finally, we shall app
ly Corollary 15 (§2.1).
This was written as a Maple procedure using the following syntax:
>
MNT:=proc(n)
global R;
local m;
m:=(2^n)

1;
R=0;
if isprime(n)=false then
R:=1;
print("MNT Test complete: Index not Prime");
elif n=2 or n=3 then
R:=1;
print("MNT Test complete: This number is PRIME");
elif n mod(4)=3 and isprime(2*n+1)=true then
R:=1;
print("MNT Test complete: NOT PRIME. Index is not of the
correct form");
else;
R:=0;
print("MNT Test complete: index n is of correct form");
end if
;
end;
The use of the global R is for the final test, and indicates whether or not the test has returned
true of false. A print screen of a typical output can be found in the Appendix (§4.3).
The next step is to test our Mersenne number for small factor
s. For this we shall need
Theorem 16 and 17 (§2.1), which gives us the form that the factor should take. Using this, the
following Maple code was written:
>
TFT:= proc(n, r)
global R;
local d,m,x,i;
m:=(2^n)

1;
x:= false;
for i to r while x= false do
d:= (2*i*n)+1;
if (d mod(8)) = 1 or (d mod(8)) =

1 then
x:=type(m/d,integer);
if x=true then print("TFT Test complete: NOT PRIME.
Trivial Factor found:");
print(d);
R:=1;
else;
end if;
end if;
Tony Skyner
Perfect Numbers
26
/
30
od;
if R=1 then
else;
print("TFT Test complete:
No trivial factors");
end if;
end;
So we now have everything we need. The final step is to bring the three tests together. The
following code is the Mersennetest procedure:
>
Mersennetest:= proc(n)
global R;
local T;
MNT(n);
if R=1 then
else;
TFT
(n, 100);
if R=1 then
else;
LLT(n);
end if;
end if;
end;
A print screen of a typical output can be found in the Appendix (§4.4). To see how effective
this procedure is, a list of increasing random positive integers was generated (using Microsoft
Exc
el), and the procedure was applied to it. The table below outlines the results.
n
Prime?
Reason For Failing
Time (
s
)
Mem (Mb)
11
No
Incorrect form
0
0
13
Yes
N/a
0.4
0
14
No
Index not prime
0
0
15
No
Index not prime
0
0
17
Yes
N/a
1.1
0
29
No
Trivia
l Factor = 233
0
0
79
No
LLT
1.0
0
117
No
Index not Prime
0
0
211
No
Trivial Factor = 15193
0
0
469
No
Index not Prime
0
0
757
No
LLT
2.7
0
2257
No
Index not Prime
0
0
5003
No
Incorrect Form
0
0
9941
Yes
N/A
83.6
38.2
14721
No
Index not Prime
0
0
21347
No
Trivial Factor = 170777
0.3
0.1
29157
No
Index not Prime
0
0
Table 3: Results of the Mersennetest procedure.
The table above should help convince the reader how rare Mersenne Primes are. It should also
be clear how useful using Number Theory a
nd Trivial Factor Tests, before applying the
Lucas

Lehmar Test, are: only two of the composites had to be verified with the Lucas

Lehmar
Test.
Tony Skyner
Perfect Numbers
27
/
30
Appendix
3.5
The Lucas

Lehmar Test
Figure 1: A typical output of the Lucas

Lehmar test, as programmed into Maple 8.
3.6
Formula For Primes Test
Figure 2: A typical outp
ut of the Formula For Primes Test, as programmed into Maple 8.
Tony Skyner
Perfect Numbers
28
/
30
3.7
Other Test
Figure 3: A typical output of the Mersenne Number Theory Test, as programme
d into Maple 8.
Tony Skyner
Perfect Numbers
29
/
30
Figure 4: A typical output of the Trivial Factors Test, as programmed into Maple 8.
3.8
Conglomerate of Tests
Figure 5: A typical output of the MersenneTest procedure, as programmed into Maple 8.
Tony Skyner
Perfect Numbers
30
/
30
4
References
Bowyer, A. Accessed 19
th
October 2004. “Formula For Primes”.
www.bath.ac.uk/~ensab/Primes/
Burton, D.M. 1980.
Elementary Number Theory
. First Edition. Allyn and Bacon, Inc. London
Caldwell, C.K. Accessed 14
th
July 2004. “Lucas

Lehmer Test (1930)”
www.utm.edu/research/primes/index.html
Dickson, L.
E.
History of the Theory of Numbers, Vol.
1
: Divisibility and Primality
.
New
York: Chelsea, 1952.
Ellis, L. Accessed 14
th
July 2004. “The History of Perfect Numbers”.
students.bath.ac.uk/ma2le/History.html
Flammenkamp, A. Accessed 27
th
November 2004. “The Multiply Perfect Number Page”
http://www
homes.uni

bielefeld.de/achim/mpn.html
Hardy, G.H. and Wright, E.M. 2002.
An Introduction to the Theory of Numbers
. Fifth
Edition. Oxford Science Publications.
O'Connor, J.J and Robertson, E.F. Accessed 14
th
July 2004. “Perfect Numbers”.
www

gap.dcs.st

an
d.ac.uk/~history/HistTopics/Perfect_numbers.html.
Sloane, N.
J.
A. “Sequences”. A000396/M4186, A000668/M2696, and A094540 in "The On

Line Encyclopedia of Integer Sequences."
www.research.att.com/~njas/sequences/
Weisstein, E.W. Accessed 14
th
July 2004.
"Perfect Number".
http://mathworld.wolfram.com/PerfectNumber.html
Woltman, G. Accessed 1
st
December 2004. “The Great Internet Mersenne Prime Search”.
www.mersenne.org
Comments 0
Log in to post a comment