Fermat Pseudoprime Calculator

Check whether a composite number passes the Fermat test to base two.

Math and PercentUpdated 2026-11-182 min read
Fermat Pseudoprime Calculator
A whole number from 3 to 1,000,000.
Classification
...
Fermat base used...
Remainder of the power...

What it does

Fermat's little theorem says that if p is prime, then two to the power p minus one leaves remainder one modulo p. A composite number that also passes this test is called a Fermat pseudoprime to base two, or a Poulet number. The first example is 341, which is 11 times 31.

Such numbers show that the Fermat test alone is not a proof of primality. They are rare enough that the test is still useful as a quick screen, but common enough that it cannot be trusted without further checks.

This page factors the input to confirm it is composite, then uses modular exponentiation to compute the remainder exactly. That avoids ever forming the enormous power of two directly.

The output shows the base, the remainder and the verdict. A composite number with remainder one is reported as a pseudoprime, while a prime is rejected by definition even though it would pass the congruence.

The input limit is one million, which keeps factoring and modular exponentiation immediate.

How to use

  1. Enter a whole number n from 3 to 1,000,000.
  2. Read the classification in the main result box.
  3. Check the base, which is always two here.
  4. The remainder is the result of two to the n minus one modulo n.
  5. The default n = 341 reproduces the worked example.
  6. Try n = 561 to see another pseudoprime.

Formula

n is a Fermat pseudoprime to base 2 when n is composite and 2^(n-1) ≡ 1 (mod n)
n
The integer being tested.
2
The Fermat base used by this page.
remainder
The value of 2^(n-1) modulo n.

Modular exponentiation squares and reduces at each step, so the computation stays small even when the exponent is large. A prime input is not reported as a pseudoprime, since the definition requires compositeness.

Worked example

Example: n = 341

The page opens with n = 341.

  1. Factor 341 as 11 x 31, confirming it is composite.
  2. Compute two to the power 340 modulo 341 using repeated squaring.
  3. The remainder is 1.
  4. The number is composite yet passes the congruence test.
  5. The tool reports Fermat pseudoprime base 2 with remainder 1.
  6. For 561 the remainder is also 1, while for 15 it is 4.

Reference table

Fermat pseudoprimes to base 2
nComposite?RemainderPseudoprime
15Yes4No
341Yes1Yes
561Yes1Yes
645Yes1Yes
1105Yes1Yes

Limits

  • Inputs above 1,000,000 are rejected to keep factoring quick.
  • Only base two is tested here.
  • Prime inputs are excluded by definition.
  • Passing the test does not prove primality.

Common mistakes

  • Reporting a prime that passes the congruence as a pseudoprime.
  • Assuming a remainder of one proves primality.
  • Computing the full power of two instead of reducing modulo n.
  • Using an even number as the exponent without subtracting one.
  • Confusing this with Carmichael numbers, which pass for every coprime base.

Try it yourself

Quick checks. Answers sit tucked under each question.

Is 341 a Fermat pseudoprime to base 2?

Yes. It is composite and 2^340 leaves remainder 1 modulo 341.

Is 15 a pseudoprime?

No. The remainder is 4.

Why use modular exponentiation?

It keeps the numbers small while giving the exact remainder.

Questions

What is a pseudoprime?

A composite number that passes a test which primes always pass.

What is a Poulet number?

A Fermat pseudoprime to base two.

Does passing prove primality?

No, that is precisely why these numbers matter.

What is the first example?

341.

Are results exact?

Yes, modular exponentiation uses integers.

What input range is accepted?

Whole numbers from 3 through 1,000,000.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.