The Fermat primality test samples integer bases a and checks whether a^(p−1) ≡ 1 (mod p). A failed check proves that p is composite; repeated successes make p only probably prime. section 8.2.2
A practical test follows this loop:
- Use an RNG to choose a base a for each iteration. section 8.2.2
- Check the congruence against candidate p; immediately reject p when it fails. section 8.2.2
- After the configured iterations, classify p as likely prime rather than certainly prime. section 8.2.2
The test is probabilistic and has a dangerous exception: Carmichael numbers such as 1,105 can pass for many bases despite being composite. Miller–Rabin is presented as a more reliable alternative. section 8.2.2
