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]
Fermat's Test by Keith Conrad. Keith Conrad, Fermat's Test, pp. 5–6, Definition 4.1 and the list beginning with 561
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 | |||||
|---|---|---|---|---|---|
| 2 | Prime number | Zero residue: excluded | 1 | 1 | 1 |
| 7 | Prime number | 1 | 1 | 1 | 1 |
| 15 | : composite number | 4 | Factor 3 | Factor 5 | 1 |
| 341 | : composite number | 1 | 56 | 67 | Factor 11 |
| 561 | : composite number | 1 | Factor 3 | 1 | Factor 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.
New to topics? Read the docs here!