Skip to content

PRP test for Mersenne numbers

Mihai Preda edited this page Jul 5, 2020 · 2 revisions

The Great Internet Mersenne Prime Search is searching for new largest prime numbers.

A Mersenne candidate (which may be prime or not) is of the form M(E)=2E-1 where the exponent E is a prime number itself. For example, the largest prime number known right now is 282'589'933-1 discovered in 2018.

The Fermat primality test is a probabilistic test to determine whether a number is a probable prime. For Mersenne candidates a common choice for the base is 3. The Fermat test would then check whether: 3p-1 =?= 1 where equality indicates that p is probable prime, while non-equality indicates that p is composite.

When p is a Mersenne number (i.e. p==2E-1) a variant of the test becomes more convenient: 3p+1 == 32E =?= 9

This (probable) primality test for Mersenne numbers, that I call PRP or PRP(3), is particularly convenient as it can be implemented, for exponent E, as a sequence of E modular squarings (called PRP iterations).

As an example, let's run the PRP test for M(7)==27-1==127. Starting with A==3 we repeatedly apply the iteration A=A2 modulo 127.

iteration residue (modulo 127)
1 9
2 81
3 84
4 71
5 88
6 124
7 9

Because the final residue is 9 (the square of our starting value A==3) the outcome of this PRP test is probable prime.

Let's now run the test for M(11)==211-1==2047.

iteration residue (modulo 2047)
1 9
2 81
3 420
4 358
5 1250
6 639
7 968
8 1545
9 223
10 601
11 929

Because the final residue is 929!=9 the outcope of this PRP test is composite.

Clone this wiki locally