Fermat primality test 2026-10-06
The Fermat test looks for a coprime base with . Such a witness proves compositeness by the Fermat little theorem, but Carmichael numbers pass for every coprime base.
The Chinese remainder theorem says that for pairwise coprime integers , any prescribed residue modulo each is realized by exactly one residue class modulo . The Fermat little theorem says that for a prime number and an integer not divisible by , ; equivalently, for every integer .
For the given prime number, write . Its square is for some integer , since one of two consecutive integers is even. Therefore . The Fermat little theorem applied modulo gives , hence ; applied modulo it gives . These applications are valid because .
The three moduli are pairwise coprime integers and have product . By the Chinese remainder theorem,
False. The Carmichael number supplies a counterexample. For every coprime to , the Fermat little theorem gives modulo each of these primes, since all divide . The Chinese remainder theorem then gives . Thus the proposed Fermat primality test can fail to detect a composite for every coprime base.
The extended Euclidean algorithm gives
Back-substituting in these equations produces the Bezout identity
Thus one integer solution is . In fact, subtracting this Bezout identity from any other solution and using that and are coprime integers gives all solutions: , , where .
For the modular arithmetic calculation, is a prime number and is coprime to it, so Fermat little theorem gives . Since , and the preceding Bezout identity identifies as the modular multiplicative inverse of , we obtain
Consequently the least positive representative is .
The auxiliary Higman group has no nontrivial finite quotients of a group. One can use this permitted property directly, but there is a short verification. In any finite quotient, let be the order of the image of . Since conjugation sends to its square, must be odd. If some , choose the least prime number dividing any . It is odd. Conjugation by the preceding generator gives
The multiplicative order of modulo is therefore a divisor of . It is greater than one and divides by the Fermat little theorem, so it has a prime divisor smaller than . That prime also divides , contradicting the choice of . Hence every and the quotient is trivial.
Given any finitely presented group , form , and apply part (a) to the word . This word is nontrivial by the normal form theorem for a free product, so the output contains by the embedding already proved.
To check its finite quotients, let be any group homomorphism to a finite group. The image of the copy of is trivial by the preceding property. The identifications make all trivial. Thus the equations give, in the image,
Since , this forces for all generators of , including . The defining word then has trivial image, so as well. Every generator of has trivial image. Therefore
This uses the concrete construction of part (a), not an assumption that arbitrary quotients preserve an embedding of .
The Fermat-Euler theorem states that
Indeed, if are the reduced residue classes modulo , multiplication by permutes them. Therefore
The product is invertible modulo , so cancellation gives the theorem.
Now let be prime. If , then for , Fermat little theorem gives , while makes . Thus for every integer .
Conversely, assume this congruence holds for every . Choose a primitive root modulo . Then . Since has order , one has . Hence
An odd composite coprime to is a Fermat pseudoprime to base when . It is a Carmichael number when this congruence holds for every coprime to .
Suppose a Carmichael number has with . The group is cyclic, so choose a residue of order
By the Chinese remainder theorem, extend it to an integer that is congruent to modulo every other prime-power factor of . Then , and the Carmichael congruence forces the order of modulo to divide . In particular , contradicting . Therefore every Carmichael number is square-free.
Now assume is square-free. If for every , then for every coprime to , Fermat little theorem gives
for each . The Chinese remainder theorem then gives the congruence modulo , so is Carmichael.
Conversely, if is Carmichael, fix . Choose a primitive root modulo and use the Chinese remainder theorem to choose and . Then , so the order of divides . This proves the Korselt criterion in the required form:
A Carmichael number cannot have one prime factor because it is composite. If with distinct primes , the condition implies , which is impossible. Hence every Carmichael number has at least three prime factors.
The Wilson theorem states that for a prime ,
Indeed, every nonzero residue modulo has a unique multiplicative inverse. The only residues equal to their own inverses solve , hence are and . Pairing every other residue with its distinct inverse leaves
The Fermat little theorem states that for prime ,
equivalently, if , then .
Wilson's theorem at gives
so . Also , and therefore