Note
Go to the end to download the full example code.
Mersenne primes and the Lucas-Lehmer test#
The Lucas-Lehmer test decides whether \(M_p = 2^p - 1\) is prime with only \(p - 2\) modular squarings. This script rediscovers every Mersenne prime with exponent below 1300 – including \(M_{521}\) through \(M_{1279}\), found by Raphael Robinson on the SWAC computer in 1952 – and plots the exponents, which grow roughly geometrically.
import matplotlib.pyplot as plt
import numpy as np
from mathematicskit.number_theory import lucas_lehmer, sieve_of_eratosthenes
Search every prime exponent below 1300#
Mersenne prime exponents: [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279]
M_1279 has 386 decimal digits
M_11 = 2047 = 23 * 89 is composite: True
Exponents grow geometrically#

Total running time of the script: (0 minutes 0.241 seconds)