Fermat's little theorem states that, for a prime number and any integer ,
If , both sides vanish modulo . Otherwise multiplication by permutes the nonzero residue classes modulo : it is injective because implies by cancellation. Taking the products of these residues gives
The factorial is coprime to , so cancellation proves and hence the stated version. This proves Fermat's little theorem in both cases.
Let be a Carmichael number. If a prime square divided , choose . Since is an odd composite integer, , and . This contradicts the required modular congruence modulo . Therefore every Carmichael number is squarefree.
For each prime divisor of , choose the allowed primitive root modulo . The Carmichael identity applied to the positive integer gives , and cancellation gives . By its defining order property,
Conversely, suppose a composite integer is squarefree and has this divisibility for every prime divisor. For an arbitrary integer , modulo a prime divisor there are two cases. If , then . Otherwise Fermat's little theorem and give , so again . Since the prime divisors are distinct and pairwise coprime, their product divides . This is the proof of Korselt criterion:
If for distinct odd primes with , the condition at would require . Reducing modulo gives , so . But , which is impossible. Thus a product of two distinct odd primes is not Carmichael.
For , squarefreeness is automatic. Since ,
Apply the analogous reductions at and to obtain
Finally , with distinct odd prime factors, and
All three divisibilities hold, so 1729 is a Carmichael number.