ForHosting KIT · Math

Fermat number generator

Type an index and see the Fermat number 2^(2^n)+1 written out in full: index 0 gives 3 and index 4 gives 65537. The digit count and the exponent 2^n come with it, for number theory lessons and contest practice. 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
N
0
You get
Fermat
3
Decimal digits
1
Exponent
1

Pierre de Fermat studied the first few values and conjectured that every F_n is prime; that conjecture fails at n equals five, where F_5 equals four billion two hundred ninety-four million nine hundred sixty-seven thousand two hundred ninety-seven and factors, yet the sequence remains central in number theory, constructible polygons, and pseudoprime tests. This generator takes a non-negative integer index n, returns the full decimal expansion of F_n as a string, reports how many digits that value has, and echoes the intermediate exponent two to the n so you can see the tower without recomputing it.

What Fermat numbers are and how F_n is defined

A Fermat number is completely determined by a single non-negative integer index n: F_n equals two raised to the power two-to-the-n, then plus one. Expanding the first indices gives the classic table students memorize: F_0 equals three, F_1 equals five, F_2 equals seventeen, F_3 equals two hundred fifty-seven, and F_4 equals sixty-five thousand five hundred thirty-seven. Those five values are all prime, which is why Fermat hoped every later term would be prime as well.

Because the exponent itself is a pure power of two, successive Fermat numbers grow double-exponentially: each step roughly doubles the bit length of the previous term. The definition never needs primality, factorization, or probabilistic tests — only exact powering and one addition. Given n, the engine computes exponent equals two to the n, forms F_n as one left-shifted by that exponent then plus one, stringifies the BigInt, and reports digit count.

Where Fermat-number generation shows up in real work

Contest programmers and olympiad coaches use small Fermat values as warm-ups before harder modular-arithmetic problems, and they need a deterministic oracle that students cannot accidentally diverge from a spreadsheet formula that overflows. Cryptography and systems engineers sometimes need known Fermat primes such as F_4 equals sixty-five thousand five hundred thirty-seven when discussing constructible regular polygons or historical RSA parameter folklore, without claiming cryptographic strength from the number alone.

If you later need Mersenne numbers, primality tests, or factorization of a general composite, treat those as separate search intents rather than overloading this Fermat-focused landing. Fermat numbers stay the right page when the question is what two to the two-to-the-n plus one equals for a given non-negative index n.

Does negative n cause an error?

Fermat numbers F_n are defined for n ≥ 0 in this generator, and the supported range is 0 through 16 inclusive.

How is F_n computed here?

The result is returned as a decimal string so large values never lose precision.

Is the result deterministic?

There is no randomness, network call, or model involved—only BigInt powering and addition.

What does it cost?

The browser tool is free and runs locally.

Are all Fermat numbers prime?

No. The first five, from F_0 (3) to F_4 (65537), are prime, which is why Fermat conjectured they all were, but F_5, which is 4294967297, factors. This generator returns the value itself and does not test whether it is prime.

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/fermat-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/fermat-number \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":4}'
{
  "n": 4
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.fermat_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.

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.

Fermat numbers are the integers F_n = 2 raised to the power of 2 to the n, plus one — written compactly as two to the two-to-the-n plus one. Negative indices are rejected with invalid_input. The same pure BigInt path runs free in the browser and on the prepaid API at $0.002 per successful item, with no network dependency, no model drift, and bit-for-bit agreement between interactive demos and automated tests.

What Fermat numbers are and how F_n is defined

That growth is why this tool returns the value as a decimal string rather than a IEEE floating-point number, and why the supported index range stops at sixteen so BigInt work stays inside Worker and browser time budgets.

Input contract, successful replies, and failure modes

Send a required integer field n. The value must be an integer from zero through sixteen inclusive. Decimals, empty fields, non-numeric strings, and values above the maximum index also fail validation and are not charged. Spot checks you can trust without a textbook open: n equals zero yields fermat three and one digit; n equals four yields sixty-five thousand five hundred thirty-seven; n equals five yields four billion two hundred ninety-four million nine hundred sixty-seven thousand two hundred ninety-seven; n equals negative one fails validation. Aliases index and k are accepted so forms, query strings, and SDK clients can reuse one contract without renaming every payload. Negative n fails with invalid_input and a message that Fermat numbers are not defined for negative indices — that is the product rule this capability enforces, matching the mathematical domain of the classical sequence. On success the JSON reports n, fermat as the full decimal string of two to the two-to-the-n plus one, decimal_digits as the length of that string, exponent equal to two raised to n, and formula as a short display string such as two caret open-paren two caret n close-paren plus one. API pricing is the published base of $0.002 per successful item; failed validation does not consume balance.

Where Fermat-number generation shows up in real work

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

Homework and olympiad warm-ups

Compute F_n = 2^(2^n)+1 for classroom indices and verify decimal expansions and digit counts against a deterministic answer key.

Deterministic fixtures for big-integer demos

Generate stable fermat and decimal_digits fields for slides, unit tests, and documentation without hand-maintaining large power-of-two strings.

Pipeline-friendly Fermat values

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

What is a Fermat number?

A Fermat number is an integer of the form F_n = 2^(2^n) + 1 for a non-negative integer index n. The first five (n = 0 through 4) are the well-known primes 3, 5, 17, 257, and 65537.

Read the full KIT documentation →