Overview
The Fermat primality test raises bases a to n - 1 modulo n and expects the result to be 1 for primes that do not divide a. It is fast, but Carmichael numbers and other pseudoprimes make it weaker than Miller-Rabin.
Checks probable primality using Fermat's congruence for selected bases.
Compact metadata for implementation and discovery.
The Fermat primality test raises bases a to n - 1 modulo n and expects the result to be 1 for primes that do not divide a. It is fast, but Carmichael numbers and other pseudoprimes make it weaker than Miller-Rabin.
Quick facts
Runtime and memory behavior at a glance.
Best
O(k)
Average
O(k^2)
Worst
O(k^3)
Space
O(k)
Show testing whether Fermat's congruence holds for selected bases on a small probabilistic primality testing example.
Fermat testing is best treated as a screen, not as a final primality decision for security-sensitive code.
What each reference supports for this entry.
Cryptographic reference for Fermat Primality Test's number-theoretic primitive, modular arithmetic, primality, or factorization context.
Open sourceReference for Fermat Primality Test's arithmetic operations, modular arithmetic, multiplication, division, or number-theoretic implementation details.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Cryptography · Core
Miller-Rabin catches many Fermat pseudoprimes by checking additional square-root conditions.
Compare with thisMiller-Rabin catches many Fermat pseudoprimes by checking additional square-root conditions.
Fermat testing may use gcd to detect bases that already share a factor with n.
The test depends on efficient modular exponentiation.