Fermat primality test Created 2026-10-06 Updated 2026-10-14
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 modular congruence first implies . Multiplication by such an permutes the nonzero residue classes modulo the prime : if , cancellation gives . Multiply all these residues and cancel their nonzero product to obtain , the usual short proof of Fermat little theorem.
Now . By the Euclid lemma, either or . In the latter case, because ,
contradicting the preceding product argument, since is odd. Thus
No unproved assertion about the number of fourth roots is needed.
For a prime number and an integer coprime to , multiplication by permutes the nonzero residue classes modulo . Indeed, implies , and none of the products is zero. Taking the product over the classes gives
The factorial is coprime to and can be cancelled, proving Fermat little theorem: .
Now and is coprime to , so it is coprime to . Since , the proved theorem gives
Thus the two specified integer congruences modulo are equivalent. In this particular step the additional hypothesis is not needed; it will hold for the squarefree factorization used next.
If is a squarefree integer, its distinct prime factors are pairwise coprime. Consequently divides exactly when every prime factor does. Applying the preceding equivalence with proves
Finally retain this squarefree hypothesis. If divides , write . Fermat little theorem gives for every prime factor. Their pairwise coprimality then gives . For composite this is the sufficient direction of the Korselt criterion for a Carmichael number; primality is not excluded by the requested implication.
The Wilson theorem says that for a prime number . Thus , and since , we get . The Fermat little theorem says when does not divide . Applying it to gives , so is the inverse of modulo . Since , the required residue is
This is the unique representative in .
For the simultaneous integer congruences, the modulus- condition is already implied by . Write ; the modulus- condition becomes , hence . The modulus- condition then gives , or . Therefore
Every such integer satisfies all four integer congruences; reversing the substitutions shows that there are no others. The uniqueness modulo also follows from the Chinese remainder theorem applied to the coprime moduli .
Since is a prime number, the Wilson theorem states that . But , so the modular inverse of , which is , gives
The Fermat little theorem states that when is prime and . Therefore , and
since . Combining these modular congruences,
This representative lies between and , so it is the least nonnegative residue.
The Fermat little theorem states that if is a prime number, then for every integer . Equivalently, for , .
To prove it when , multiplication by permutes the nonzero residues . Indeed, implies , and the Euclid lemma implies in this range. Multiplying all these residues gives
None of the factors of is divisible by , so the factorial has a modular inverse. Cancelling it proves , hence . When , the latter identity has both sides zero, completing the proof.
For an odd prime number , the numbers are coprime. The Fermat little theorem gives , and consequently
These exponents are distinct, so infinitely many are obtained.
Write the repdigit with copies of as
If , choose to be any positive multiple of . Then has a modular inverse modulo , so . Division by cannot be used modulo ; instead gives , so for every . If , every is divisible by . Thus
The separate treatment of accounts for the prime factor of the geometric-sum denominator.
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
Repdigit Created 2026-10-14 Updated 2026-10-20
A repdigit is a positive integer whose base- expansion repeats one nonzero digit . For , and , the finite geometric series gives . For example, has decimal digits, all equal to five.
Every prime number not dividing divides infinitely many such repdigits. If it divides , every length works. Otherwise, if it does not divide , the Fermat little theorem gives divisibility for lengths that are multiples of , and division by is justified by its modular inverse. If , the sum is congruent to modulo , so lengths divisible by work instead. A prime dividing but not divides none, since . This distinction prevents invalid cancellation of the geometric-sum denominator.