Skip to content
Omnikalc

Mersenne prime calculator: how many digits does 2^p − 1 have?

Enter the exponent p to get the number of digits of 2^p − 1 and of the matching perfect number, the storage size, the Lucas-Lehmer steps and the pages to print it.

Updated on
Your inputs

Value out of range

Results

Digits of the Mersenne number 2^p − 1

24,862,048

Digits of the perfect number 2^(p−1) × (2^p − 1)
49,724,095
Storage of the Mersenne number
10.324 MB
Lucas-Lehmer steps to test it
82,589,931
Pages to print the Mersenne number (3,000 digits per page)
8,287

Mersenne numbers, 2^p − 1, hold the record for the largest known primes, and they give the even perfect numbers. The Mersenne prime calculator takes the exponent p and gives the number of digits of 2^p − 1, the digits of the matching perfect number, the storage size, the Lucas-Lehmer steps and the pages needed to print the number.

How the calculation works

  • Digits of the Mersenne number 2^p − 1 = floor(p × log10 2) + 1. The −1 never changes the digit count, because a power of 2 is not a power of 10.
  • Digits of the perfect number 2^(p−1) × (2^p − 1) = floor((2p − 1) × log10 2) + 1. Euclid and Euler showed that when 2^p − 1 is prime, this number is perfect, equal to the sum of its proper divisors.
  • Storage = p ÷ 8 bytes, since the number has p bits, all equal to 1.
  • Lucas-Lehmer steps = p − 2. The test squares a number modulo 2^p − 1 that many times, and is the way record primes are found.

Example

The largest known Mersenne prime in 2018 was 2^82,589,933 − 1. Its digit count is floor(82,589,933 × 0.30103) + 1 = 24,862,048. The perfect number built from it has floor(165,179,865 × 0.30103) + 1 = 49,724,095 digits. Stored in binary it takes 82,589,933 ÷ 8 ≈ 10.32 MB, and the Lucas-Lehmer test needs 82,589,931 squarings. Printed at 3,000 digits per page, the Mersenne number would fill about 8,287 pages.

Why it matters

The numbers are so large that their size is hard to picture. A page count, a file size and a number of steps make it concrete, which helps in teaching number theory and in explaining what distributed computing projects do.

Good to know

The digit counts are exact for any exponent. The calculator does not decide if the number is prime, and not every prime p gives a prime 2^p − 1: for example 2^11 − 1 = 2047 = 23 × 89. For very large p the displayed values are rounded to the precision of the screen.

The Catalan number calculator and the combinations calculator give other quickly growing counts from combinatorics.

Frequently asked questions

What is a Mersenne prime?

A Mersenne prime is a prime number of the form 2^p − 1, where p is itself prime. The first ones are 3, 7, 31 and 127. Only 51 are known, and the largest has more than 24 million digits. Most record primes of the last decades are Mersenne primes, found by the GIMPS distributed project.

What is a perfect number?

A perfect number equals the sum of its proper divisors. The first is 6 (1 + 2 + 3), then 28, 496 and 8128. Euclid proved that 2^(p−1) × (2^p − 1) is perfect when 2^p − 1 is prime, and Euler proved that every even perfect number has this form. No odd perfect number is known.

Does the calculator check that the number is prime?

No. It gives the size of 2^p − 1 for any exponent. The number is prime only for some prime exponents, and the test is the Lucas-Lehmer test, which takes about as many steps as p − 2 with very large number arithmetic. The result is therefore valid for the size, but it is not a primality proof.

Why are Mersenne numbers used to find large primes?

Their special form allows a fast and simple primality test, the Lucas-Lehmer test, that works much faster than general tests on numbers of the same size. This is why the record for the largest known prime has been held by a Mersenne prime for most of the computer age.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.