CARMICHAEL NUMBERS AND KORSELT’S CRITERION

KEITH CONRAD

Fermat’s little theorem says for a prime p and all a 6≡ 0 mod p that ap−1 ≡ 1 mod p. Conversely, if n > 1 and an−1 ≡ 1 mod n for all a 6≡ 0 mod n then n must be prime: from an−1 ≡ 1 mod n we get (a, n) = 1, so n is relatively prime to all integers from 1 to n − 1, and thus n is a . While a 6≡ 0 mod p is the same as (a, p) = 1 when p is prime and a is any , the conditions a 6≡ 0 mod n and (a, n) = 1 are not the same when n is composite: (a, n) = 1 ⇒ a 6≡ 0 mod n but the converse is usually false (depending on a). If we write a 6≡ 0 mod p with (a, p) = 1 in Fermat’s little theorem, making it “(a, p) = 1 =⇒ ap−1 ≡ 1 mod p,” we have an implication that is sometimes true if we replace prime p by composite n. Definition 1. An integer n > 1 is called a Carmichael number if n is composite and (a, n) = 1 =⇒ an−1 ≡ 1 mod n for all a ∈ Z. Initially it is not at all clear that there should be any Carmichael numbers, but the first few were found by Robert Carmichael [1], [2] in the early 20th century and they are 561, 1105, 1729, 2465, 2821. It is possible to verify that an integer n is a Carmichael number without using the definition, so not having to check an−1 ≡ 1 mod n for all a that are relatively prime to n. Instead we can check a property of the prime factorization of n known as Korselt’s criterion. Theorem 2 (Korselt). A composite integer n > 2 is a Carmichael number if and only if (i) n is squarefree and (ii) for every prime p dividing n, also (p − 1) | (n − 1). Proof. Assume n is a Carmichael number. First we will show n is squarefree. If a prime p divides n more than once, write n = pkn0 where k ≥ 1 and (p, n0) = 1. We want to show k = 1, and will do this by contradiction using the Chinese remainder theorem. Assume k ≥ 2, so n is divisible by p2. By the Chinese remainder theorem there is an a ∈ Z such that a ≡ 1 + p mod pk and a ≡ 1 mod n0. Then (a, n) = 1, so an−1 ≡ 1 mod n by the definition of Carmichael numbers. Reduce the above congruence modulo p2, getting (1 + p)n−1 ≡ 1 mod p2. By the binomial theorem, (1 + p)n−1 ≡ 1 + (n − 1)p mod p2. Since n is divisible by p, 1+(n−1)p ≡ 1−p mod p2. Thus 1−p ≡ 1 mod p2. This is a contradiction, so k = 1. Next we show (p − 1) | (n − 1) for each prime p dividing n. Since n is squarefree, p and n/p are relatively prime. Pick any b ∈ Z such that b mod p has order p − 1 (there is a primitive root modulo any prime). By the Chinese remainder theorem there’s an a ∈ Z such that a ≡ b mod p and a ≡ 1 mod n/p, so (a, n) = 1. Then an−1 ≡ 1 mod n. Reducing both sides modulo p, bn−1 ≡ 1 mod p. This implies, by the choice of b, that (p−1) | (n−1). Now assume n is squarefree and (p − 1) | (n − 1) for every prime p that divides n. We want to show n is Carmichael. If a ∈ Z satisfies (a, n) = 1 then for each prime p dividing n we have (a, p) = 1, so ap−1 ≡ 1 mod p. Since p−1 is a factor of n−1 we get an−1 ≡ 1 mod p. 1 2 KEITH CONRAD

As this holds for all primes p dividing n, and n is squarefree, we get an−1 ≡ 1 mod n. Also n is composite (hypothesis), so n is Carmichael.  Korselt [4] proved this theorem about 10 years before Carmichael essentially rediscovered it [1], [2], but Korselt was unable to find examples of such numbers and that is why they are called Carmichael numbers. On that basis, however, these numbers should be called Simerka˘ numbers since V. Simerka˘ found the first 7 examples 25 years before Carmichael. Below is an excerpt from Simerka’s˘ article [5], which appeared in a Czech math journal that was not widely read.

Figure 1. Carmichael numbers found by Simerka˘ before Carmichael.

Example 3. We use Korselt’s criterion to verify a construction of Carmichael numbers due to Chernick [3]: if k is a positive integer such that 6k + 1, 12k + 1, and 18k + 1 are all prime then the product n = (6k + 1)(12k + 1)(18k + 1) is a Carmichael number. For instance, 7 · 13 · 19 = 1729 is a Carmichael number. The first condition of Korselt’s criterion, that n be squarefree, obviously holds. To check the second criterion we want to show n − 1 is divisible by 6k, 12k, and 18k. Since 6 | 12 it suffices to look at n mod 12k and n mod 18k. Modulo 12k we have n ≡ (6k + 1)(6k + 1) ≡ 1 mod 12k, and modulo 18k we have n ≡ (6k + 1)(12k + 1) ≡ 1 mod 18k. Thus n − 1 is divisible by the desired factors, so it is a Carmichael number when its three factors are all prime. This method of Chernick is very convenient if you want to construct an example of a large Carmichael number, such as if you are giving a lecture on Carmichael numbers and want to give an example other than the same examples that are in all the books. Run a computer algebra package to find big k where 6k + 1, 12k + 1, and 18k + 1 are all prime (it’s believed this should happen infinitely often, and in any case it usually doesn’t take long to find such a choice of k), take their product, and you’re done. As an exercise, verify with Korselt’s criterion that if 6k + 1, 12k + 1, 18k + 1, and 36k + 1 are all prime then their product is a Carmichael number. Corollary 4. A composite integer n is a Carmichael number if and only if an ≡ a mod n for all a ∈ Z. Proof. If an ≡ a mod n for all a ∈ Z, then when (a, n) = 1 we can cancel a from both sides and get an−1 ≡ 1 mod n, so n is a Carmichael number since it is composite. Conversely, assume n is Carmichael. To prove, for each a ∈ Z, that an ≡ a mod n it suffices since n is squarefree to prove an ≡ a mod p for each prime p dividing n. This congruence is obvious if a ≡ 0 mod p. If a 6≡ 0 mod p then ap−1 ≡ 1 mod p by Fermat’s n−1 n little theorem, and p−1 is a factor of n−1, so a ≡ 1 mod p, and thus a ≡ a mod p.  CARMICHAEL NUMBERS AND KORSELT’S CRITERION 3

Here are some further properties (but not characterizations) of Carmichael numbers.

Theorem 5. Every Carmichael number √n is odd, has at least three different prime factors, and every prime factor of n is less than n. Proof. Since n − 1 is relatively prime to n, we have (n − 1)n−1 ≡ 1 mod n, so (−1)n−1 ≡ 1 mod n and we know (−1)n−1 = ±1. Since n > 2 we have −1 6≡ 1 mod n, so (−1)n−1 = 1. Thus n − 1 is even, so n is odd. Suppose n = pq for primes p and q. Since n is squarefree, p 6= q. We may assume without loss of generality that p > q. By Korselt’s criterion, (p − 1) | (n − 1). Since n − 1 pq − 1 (p − 1)q + q − 1 q − 1 = = = q + , p − 1 p − 1 p − 1 p − 1 we must have (p − 1) | (q − 1). But this is impossible since q − 1 < p − 1. Thus n has at least three different prime factors. If p is a prime factor of n, then n − 1 p(n/p) − 1 (p − 1)(n/p) + n/p − 1 n n/p − 1 = = = + , p − 1 p − 1 p − 1 p p − 1 2 so (p − 1) | (n/p − 1). Thus p√≤ n/p, and the inequality must be strict (otherwise n = p , which is impossible), so p < n. Incidentally,√ this gives√ another proof that√ √n has at least three prime factors: if n = pq with p < n and q < n then n = pq < n n = n, which is a contradiction.  References [1] R. D. Carmichael, Note on a New Function, Bulletin Amer. Math. Soc. 16 (1910), 232–238. [2] R. D. Carmichael, On composite P which satisfy the Fermat congruence aP −1 ≡ 1 mod P , Amer. Math. Monthly 19 (1912), 22–27. [3] J. Chernick, On Fermat’s simple theorem, Bull. Amer. Math. Soc. 45 (1939), 269–274. [4] A. R. Korselt, Probl`emechinois, L’interm´ediairedes math´ematiciens 6 (1899), 142–143. [5]V. Simerka˘ Zbytky z arithemetick´e posloupnosti (On the remainders of an arithmetic progression), Casopis˘ pro p˘estov´an´ı matematiky a fysiky 14 (1885), 221–225. Online at https://gdz.sub. uni-goettingen.de/id/PPN31311028X 0014.