Fermat test example 2026-10-14
For the Fermat primality test, a passing base satisfies . Passing proves only this modular congruence, not that is a prime number. An odd composite number that passes a coprime base is a Fermat pseudoprime to that base. A Carmichael number passes every coprime base, so even testing all the units would not certify that is a prime number. [ref]
This small table uses only the bases , each reduced modulo first. A numeric entry is : one passes, while any other numeric entry gives a Fermat witness. A "factor" entry records a proper greatest common divisor and stops before modular exponentiation. The prime/composite classification is independently established by trial division or the displayed prime factorization, not by the passing entries. These four bases are illustrative, with no asserted universal coverage or error probability.
Table 1.
Finite-base Fermat primality test examples with explicit greatest common divisor checks
.
Independent classification
2Prime numberZero residue: excluded111
7Prime number1111
15: composite number4Factor 3Factor 51
341: composite number15667Factor 11
561: composite number1Factor 31Factor 11
For , and , so . Yet and , so three is a Fermat witness. One coprime base passes and another fails: being a Fermat pseudoprime depends on the base. Choosing eleven instead reveals the proper factor through .
For , every coprime base passes: each of divides , so Fermat's little theorem gives modulo each prime factor; the Chinese remainder theorem combines the three modular congruences. Equivalently, the Carmichael function gives . Bases two and five have greatest common divisor one and pass, but , and expose factors. The qualification "coprime" is therefore crucial even for a Carmichael number.
The Fermat primality test is useful because a Fermat witness can prove compositeness using repeated squaring without finding a factor. Its failure to certify a passing candidate motivates stronger primality testing methods such as the Miller-Rabin primality test.
By the definition of Fermat pseudoprime, is composite as well as odd, and . Put . A proper factorization makes a proper divisor of , so is composite. Now
Since , . This is the first passing condition of the Miller-Rabin primality test, with . Thus is a base-two strong pseudoprime. If “pseudoprime” were used to include primes, the compositeness conclusion would fail, for instance gives ; the standard composite definition matters.
The Miller-Rabin primality test first handles as prime and or even as composite. For odd , write with odd and choose a base . A nontrivial proves compositeness. Otherwise compute : the round passes if or . If neither holds, square successively, at most times, and pass if a value occurs; otherwise declare composite. An occurrence of before exhibits a nontrivial square root of one and is also a failure. For prime , Fermat's theorem and the fact that a field has only the square roots force a pass. The standard strong-liar bound says that an odd composite passes for at most one quarter of the bases; independent random rounds therefore have error probability at most after rounds. Passing is a probable-prime verdict, not a proof of primality. A Fermat pseudoprime is composite and passes ; a strong pseudoprime is composite and passes the stronger round above.