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]
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.
Past exam of the mathematics course of the University of Cambridge 2010 ii Paper 3 11G ii Solution Created 2026-09-24 Updated 2026-10-14
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. NowSince , . 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.
Past exam of the mathematics course of the University of Cambridge 2010 ii Paper 3 11G Solution 2026-10-14
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.