Test whether 2ⁿ − 1 is a Mersenne prime for a given exponent n.
A Mersenne prime is a prime number of the form Mₙ = 2ⁿ − 1. A necessary (but not sufficient) condition is that n itself is prime. Known Mersenne prime exponents include 2, 3, 5, 7, 13, 17, 19, 31, 61. Primality here is decided by the Lucas–Lehmer test, which settles Mₙ in n − 2 exact modular squarings; the n ≤ 61 cap is so that 2ⁿ − 1 (up to ≈ 2.3×10¹⁸) can still be shown in full.
Mersenne number
M(n) = 2^n − 1
If n = a × b with a,b > 1, then 2ⁿ − 1 is divisible by 2ᵃ − 1, so it cannot be prime. Therefore n must be prime — but that alone is not sufficient (e.g. M(11) = 2047 = 23 × 89).
As of 2024, 51 Mersenne primes are known. The smallest exponents are 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, … The largest known prime is always a Mersenne prime.