ForHosting KIT · Math

Mersenne number checker

Enter an exponent and get the full value of 2^p − 1 with a prime verdict: 7 gives 127, a Mersenne prime, while 11 gives 2047, which is 23 × 89. Exponents run from 2 to 10,000. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Power (W)
7
You get
Mersenne
127
Decimal digits
3

When Mp itself is prime, it is called a Mersenne prime—numbers that have driven record searches for centuries, from Marin Mersenne’s early lists through modern distributed projects. Not every exponent yields a prime: if p is composite then Mp is composite, and even for many prime exponents the Mersenne number factors (for example 2^11 − 1 = 2047 = 23 × 89). This tool takes an integer exponent p at least two, returns the full decimal value of 2^p − 1 as a string, and decides whether that value is prime using the deterministic Lucas-Lehmer test when p is an odd prime.

What Mersenne numbers are and how Lucas-Lehmer decides

The first few values are familiar classroom constants—M2 equals three, M3 equals seven, M5 equals thirty-one, M7 equals one hundred twenty-seven—while larger exponents produce integers with thousands of decimal digits. A Mersenne prime is simply a Mersenne number that is prime. A classical necessary condition is that the exponent p itself must be prime: if p factors as ab with a and b greater than one, then 2^a − 1 divides 2^{ab} − 1, so Mp cannot be prime.

That necessary condition is not sufficient. For p equals eleven, which is prime, M11 equals two thousand forty-seven and factors as twenty-three times eighty-nine. The Lucas-Lehmer test settles the question completely for odd prime exponents.

Start with s zero equal to four; for each of the next p minus two steps replace s with s squared minus two, reduced modulo Mp. The Mersenne number is prime if and only if the final residue is zero. For the special case p equals two the number three is prime by inspection and does not need the iterative sequence.

This capability implements that exact pipeline with BigInt arithmetic: it never approximates, never calls a primality service, and never depends on wall-clock time or random bits.

Where Mersenne checks show up in real work

Contest programmers and olympiad coaches use small Mersenne checks as warm-ups before harder modular-arithmetic problems, and they need a deterministic oracle that students cannot accidentally diverge from a spreadsheet formula. Cryptography and systems engineers sometimes sanity-check teaching demos or historical tables of known Mersenne primes without claiming cryptographic strength from a single modular sequence. If you later need twin pairs, π(n), or factorization of a general composite, treat those as separate search intents rather than overloading this Mersenne-focused landing.

Mersenne numbers stay the right page when the question is what 2^p − 1 equals and whether Lucas-Lehmer (or the composite-exponent rule) certifies it as a Mersenne prime.

What is a Mersenne number?

When that number is prime, it is called a Mersenne prime.

Does p below 2 cause an error?

The checker only accepts exponents from 2 through 10,000 inclusive.

How does Lucas-Lehmer work here?

Mp is prime if and only if the final residue is zero. Composite exponents skip the loop and are reported composite.

Is the result deterministic?

There is no randomness, network call, or model involved—only BigInt modular arithmetic and trial division of the exponent.

What does it cost?

The browser tool is free and runs locally.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/mersenne-number

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/mersenne-number \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"p":7}'
{
  "p": 7
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.mersenne_number",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

min_p2
max_p10000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

A Mersenne number is an integer of the special form Mp = 2^p − 1, where p is a positive integer exponent.

What Mersenne numbers are and how Lucas-Lehmer decides

A Mersenne number is defined by a single exponent: Mp equals two raised to the power p, minus one. You always get the same boolean for the same p.

Input contract, successful replies, and failure modes

Decimals, empty fields, and non-numeric strings fail validation and are not charged. Send a required integer field p (aliases exponent and power are accepted). The value must be at least two—exponents below two are rejected with invalid_input so forms surface a clear bound error—and at most ten thousand so modular squaring stays within Worker and browser budgets. On success the JSON reports p, the full decimal string mersenne for two to the p minus one, decimal_digits as the digit count of that string, p_is_prime for the exponent, is_mersenne_prime for Mp, and method describing which path ran: special_case_p2 for the classical three, composite_exponent when p is composite (Mp is then known composite without iterating Lucas-Lehmer), or lucas_lehmer when p is an odd prime. Spot checks you can trust without a textbook open: p equals seven yields mersenne one hundred twenty-seven and is_mersenne_prime true; p equals eleven yields two thousand forty-seven and false; p equals four yields mersenne fifteen with composite_exponent and false; p equals one fails validation. API pricing is the published base of $0.002 per successful item; failed validation does not consume balance.

Where Mersenne checks show up in real work

Because the capability is a pure parse engine, the same p always yields the same JSON with no network dependency and no stored state.

Homework and olympiad warm-ups

Compute Mp = 2^p − 1 for classroom exponents and verify which values are Mersenne primes with a deterministic Lucas-Lehmer answer key.

Deterministic fixtures for number-theory demos

Generate stable mersenne and is_mersenne_prime fields for slides, unit tests, and documentation without hand-maintaining large decimal strings.

Pipeline-friendly Mersenne checks

Call the same isomorphic contract from scripts and CI so Mersenne primality assertions never depend on a casual web form or a language model.

Read the full KIT documentation →