# 费马伪素数

**费马伪素数**（Fermat pseudoprime）以 a 为底，是指满足同余式 a^(n−1) ≡ 1 (mod n) 的合数 n，这与费马小定理对所有与 a 互素的素数 n 所保证的同余式相同。因此这类数虽然本身是合数，却能通过费马合数检验；以 2 为底的最小例子是 341 = 11·31。<sup>[1](https://oeis.org/A001567)</sup><sup> • </sup><sup>[2](https://t5k.org/prove/prove2_2.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 满足 a^(n−1) ≡ 1 (mod n) 的合数 n；以 2 为底的例子常被简称为伪素数，或称普莱数（Poulet number）<sup>[1](https://oeis.org/A001567)</sup><sup> • </sup><sup>[3](https://mathworld.wolfram.com/FermatPseudoprime.html)</sup> |
| 最小例子 | 341 = 11·31（以 2 为底，1819 年由萨吕斯（Sarrus）注意到）；91 = 7·13（以 3 为底）；217 = 7·31（以 5 为底）；25 = 5·5（以 7 为底）<sup>[2](https://t5k.org/prove/prove2_2.html)</sup> |
| 10^6 以下的计数 | 245 个以 2 为底的伪素数，114 个欧拉伪素数，46 个强伪素数，43 个卡迈克尔数<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup> |
| 卡迈克尔数 | 对所有互素底数均为伪素数的合数；最小者为 561 = 3·11·17；有无穷多个，当 x 充分大时其计数超过 x^0.33<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup> |
| 强伪素数 | 比同底的费马伪素数大约稀少四倍；以 2 为底的最小例子是 2047 = 23·89<sup>[6](https://ntheory.org/pseudoprimes.html)</sup><sup> • </sup><sup>[7](https://www.cecm.sfu.ca/Pseudoprimes/)</sup> |
| 误差界 | 任何奇合数 n 都不可能对所有底数中超过 1/4 的比例成为强伪素数，因此随机底数的米勒–拉宾检验每轮出错的概率至多为 1/4<sup>[8](https://gmplib.org/manual/Prime-Testing-Algorithm)</sup> |
| 实际应用 | GMP 的 mpz_probab_prime_p 先用小因子做试除，再用随机底数做米勒–拉宾检验<sup>[8](https://gmplib.org/manual/Prime-Testing-Algorithm)</sup> |

## 定义与最初的例子

费马小定理指出，若 n 为素数且 gcd(a, n) = 1，则 a^(n−1) ≡ 1 (mod n)。满足同一同余式的合数 n 称为以 a 为底的费马伪素数，记作 psp(a)。一些作者还额外要求 n 为奇数，波梅兰斯（Pomerance）、塞尔弗里奇（Selfridge）和瓦格斯塔夫（Wagstaff）在 1980 年编制的表格中便采用了这一要求，这样就会把 4 排除在 psp(5) 之外。<sup>[3](https://mathworld.wolfram.com/FermatPseudoprime.html)</sup> 当 gcd(a, n) = 1 时，这等价于 a^n ≡ a (mod n)；波梅兰斯也使用后一条件，但不要求 gcd(a, n) = 1。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup>

以 2 为底的最小伪素数依次为 341、561、645、1105、1387、1729、1905、2047、2465、2701。<sup>[1](https://oeis.org/A001567)</sup> 以 3 为底的最小者是 91 = 7·13，以 5 为底是 217 = 7·31，以 7 为底是 25 = 5·5。<sup>[2](https://t5k.org/prove/prove2_2.html)</sup> 以 2 为底的伪素数称为普莱数，较少见的叫法是萨吕斯数或费马数。<sup>[3](https://mathworld.wolfram.com/FermatPseudoprime.html)</sup>

通常的定义只考虑奇合数，这是有充分理由的：第一个以 2 为底的偶伪素数 161038 = 2·73·1103，直到 1950 年才被发现。<sup>[9](https://math.gordon.edu/ntic/ntic2021-7/section-probable-primes.html)</sup> 而 a^n ≡ a 的形式在 gcd(a, n) > 1 时仍有意义。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup>

## 合数为何能通过费马检验

“骗子”底数的结构并非随机。对于奇合数 n，使 n 成为伪素数的底数集合构成模 n 的既约剩余类乘法群的一个子群；由于雅可比符号具有乘性，欧拉伪素数的底数集合同样如此。<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup> 卡迈克尔数能骗过整个群，也就是说，每个互素底数都是骗子底数。<sup>[2](https://t5k.org/prove/prove2_2.html)</sup>

然而这个子群终究只占少数。对于奇合数 n > 9，在 1 到 n 之间，至多有 φ(n)/4 个底数 a 使 n 成为以 a 为底的强伪素数，其中 φ 是欧拉函数。<sup>[10](https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch12.pdf)</sup><sup> • </sup><sup>[21](https://mathworld.wolfram.com/CarmichaelNumber.html)</sup> 更一般地，对于不是卡迈克尔数的合数 n，在 [1, n] 中与 n 互素的底数 x 中至多有一半是费马骗子；但卡迈克尔数对所有与 n 互素的底数都是伪素数，所以 561 在其 561 个剩余类中有 320 个能通过，超过了 2^(1−3) = 1/4。<sup>[11](https://doi.org/10.4064/aa230512-17-2)</sup><sup> • </sup><sup>[22](https://math.dartmouth.edu/~carlp/evenpsps032725.pdf)</sup> 一个数若在某个底数下通过检验而未知其为合数，则称为概率素数；这个称呼刻意弱于素性证明。<sup>[12](https://mathworld.wolfram.com/FermatsLittleTheorem.html)</sup>

## 卡迈克尔数

**最坏情形。** 若合数 n 对所有与 n 互素的整数 a 都满足 a^(n−1) ≡ 1 (mod n)，则 n 是卡迈克尔数。前三个是 561、1105 和 1729。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup> 希梅尔卡（V. Šimerka）于 1885 年发现了最初的七个例子；卡迈克尔于 1910 年公布了最初的例子，这类数便以他命名。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup><sup> • </sup><sup>[13](https://link.springer.com/article/10.1007/s40993-024-00598-3)</sup> 100,000 以下的十六个卡迈克尔数是 561、1105、1729、2465、2821、6601、8911、10585、15841、29341、41041、46657、52633、62745、63973 和 75361。<sup>[2](https://t5k.org/prove/prove2_2.html)</sup>

对于卡迈克尔数 n，费马检验返回“可能为素数”的概率为 (φ(n) − 1)/(n − 2)，当 n 只有少数几个大素因子时该值接近 1，因此费马检验对它们基本上无能为力。<sup>[14](https://isa-afp.org/browser_info/current/AFP/Probabilistic_Prime_Tests/outline.pdf)</sup> 依次以 2、3、5 等为底反复做概率素数检验，都无法揭示卡迈克尔数是合数，直到用它的某个因子作底数为止。<sup>[2](https://t5k.org/prove/prove2_2.html)</sup>

**无穷性与密度。** 1956 年厄多斯（Erdős）证明了伪素数与卡迈克尔数计数函数的指数型上界，但当时并不知道卡迈克尔数是否有无穷多个。<sup>[15](https://www.renyi.hu/~p_erdos/1956-10.pdf)</sup> 1994 年奥尔福德（Alford）、格兰维尔（Granville）和波梅兰斯证明了卡迈克尔数有无穷多个；对所有充分大的 x，其计数超过 x^0.33。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup> 另一方面，对所有充分大的 x，x 以下的卡迈克尔数至多为 x/L(x)，其中 L(x) 是增长缓慢的函数，人们猜想在 x/L(x)^(1+o(1)) 的形式下这已接近最优。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup> 在 X 约为 10^16 时，计算所得的计数增长大致如 X^0.337。<sup>[16](https://ar5iv.labs.arxiv.org/html/math/9803082)</sup>

## 数据一览

以 2 为底的费马伪素数（整数数列线上大全 A001567）在 10 的各次幂以下的计数为：10^9 以下 5597 个，10^10 以下 14884 个，10^11 以下 38975 个，10^12 以下 101629 个，10^13 以下 264239 个，10^14 以下 687007 个，10^15 以下 1801533 个。<sup>[6](https://ntheory.org/pseudoprimes.html)</sup> 10^6 以下有 245 个。<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup> 费茨马（Feitsma）计算了 2^64 ≈ 1.8·10^19 以下全部 118,968,378 个以 2 为底的伪素数；结合 2^64 以下 425,656,284,035,217,742 个奇素数，这意味着 2^64 以下以 2 为底的概率素数中有 99.9999999721% 实际上是素数。<sup>[17](https://arxiv.org/pdf/2006.14425v2.pdf)</sup>

与素数的对比解释了亨利·科恩（Henri Cohen）的玩笑：以 2 为底的概率素数是“工业级素数”：在 25,000,000,000 以下有 1,091,987,405 个素数，却只有 21,853 个以 2 为底的伪素数。<sup>[2](https://t5k.org/prove/prove2_2.html)</sup> 卡迈克尔数更为稀少：10^9 以下 646 个，平奇（Pinch）的表格中 10^12 以下 8241 个，10^16 以下 246,683 个，10^22 以下 49,679,870 个。<sup>[13](https://link.springer.com/article/10.1007/s40993-024-00598-3)</sup><sup> • </sup><sup>[16](https://ar5iv.labs.arxiv.org/html/math/9803082)</sup>

## 强化检验：欧拉伪素数与强伪素数

存在两种更严格的概念。以 b 为底的欧拉伪素数是满足 gcd(b, n) = 1 且 b^((n−1)/2) ≡ (b/n) (mod n) 的奇合数 n，其中 (b/n) 是雅可比符号；以 b 为底的强伪素数则通过序列 b^(s·2^i) mod n 定义，其中 n − 1 = 2^r·s 且 s 为奇数。对每个与 n 互素的底数 b，蕴含关系 强 ⇒ 欧拉 ⇒ 普通伪素数 成立。<sup>[18](https://encyclopediaofmath.org/wiki/Pseudo-prime)</sup> 以 a 为底的伪素数中约有一半是欧拉伪素数，因此欧拉判别法比费马同余式略强。<sup>[17](https://arxiv.org/pdf/2006.14425v2.pdf)</sup>

强条件筛选得更为激进。以 2 为底的强伪素数（整数数列线上大全 A001262）在相同界限下的计数为：10^9 以下 1282 个，10^12 以下 22407 个，10^15 以下 419489 个，大约比费马伪素数稀少四倍。<sup>[6](https://ntheory.org/pseudoprimes.html)</sup> 前十个以 2 为底的强伪素数是 2047、3277、4033、4681、8321、15841、29341、42799、49141 和 52633；2047 = 23·89 是最小的一个，而 341 是费马伪素数但不是强伪素数。<sup>[11](https://doi.org/10.4064/aa230512-17-2)</sup><sup> • </sup><sup>[7](https://www.cecm.sfu.ca/Pseudoprimes/)</sup>

决定性的结构差异在于强检验没有卡迈克尔式的对应物：根据拉宾定理，不存在合数 n 对所有 x ∈ (Z/nZ)× 都是以 x 为底的米勒–拉宾伪素数。<sup>[11](https://doi.org/10.4064/aa230512-17-2)</sup> 结合骗子底数不超过 1/4 的界，这使得随机底数的米勒–拉宾检验具有费马检验无法企及的可靠性。<sup>[8](https://gmplib.org/manual/Prime-Testing-Algorithm)</sup>

关于组合底数的一点提醒：强伪素数的底数集合不必对乘法封闭。数 n = 2284453 = 1069·2137 是以 2 和 7 为底的强伪素数，但不是以 14 为底的强伪素数。<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup> 尽管如此，固定的底数集合可以在某个范围内做到穷尽：以 2、3、5 为底检验强伪素性，能正确判定任何 n < 25,326,001 的素性。<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup><sup> • </sup><sup>[23](https://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html)</sup>

## 在实际素性检验中的作用

GMP 的 mpz_probab_prime_p 先用小因子做试除，然后按克努特（Knuth）第 4.5.4 节算法 P 所述应用米勒–拉宾概率算法。对于奇数 n = q·2^k + 1（q 为奇数），它选取随机底数 x，检验 x^q mod n 是否为 1 或 −1，或者是否存在某个 1 ≤ j < k 使 x^(q·2^j) mod n 为 −1；通过则意味着可能为素数，不通过则意味着确定为合数。<sup>[8](https://gmplib.org/manual/Prime-Testing-Algorithm)</sup> 由于任何奇合数 n 都不可能对所有合格底数中超过 1/4 的比例通过米勒–拉宾检验，随机底数宣布合数 n 可能为素数的机会至多为 1/4；实际上强伪素数远比这个界所暗示的稀少，但对任意 n 能证明的只有 1/4。<sup>[8](https://gmplib.org/manual/Prime-Testing-Algorithm)</sup><sup> • </sup><sup>[24](https://crypto.stanford.edu/pbc/notes/numbertheory/millerrabin.html)</sup> 用 O(log n) 个随机底数运行该检验，总复杂度为 O(log(n)^4) 次位运算。<sup>[10](https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch12.pdf)</sup>

固定小底数不够用的原因在于子群结构：卡迈克尔数能通过每个互素底数，因此一串固定的小底数要么全部一起通过，要么最终必然撞上 n 的某个因子。<sup>[4](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)</sup><sup> • </sup><sup>[2](https://t5k.org/prove/prove2_2.html)</sup>

## 近期进展

2024 年的一份表格报告了 10^22 以下 49,679,870 个卡迈克尔数，比理查德·平奇（Richard Pinch）先前的工作提高了一个数量级。<sup>[13](https://link.springer.com/article/10.1007/s40993-024-00598-3)</sup> 作为参照，10^21 以下有 20,138,200 个卡迈克尔数。<sup>[19](https://math.mit.edu/classes/18.783/2025/LectureNotes11.pdf)</sup> 2026 年《美国数学月刊》的一篇文章研究了固定底数费马伪素数的渐近密度，并重申了标准定义：满足 a^(n−1) ≡ 1 (mod n) 的合数整数是以 a 为底的费马伪素数。<sup>[20](https://www.tandfonline.com/doi/full/10.1080/00029890.2026.2722582)</sup> 波梅兰斯的综述列出了 10^16 以下所有偶伪素数，并证明了奥尔多大斯基（Ordowski）的一个猜想：存在某个真因子作为底数使 n 成为伪素数的整数 n 的集合具有渐近密度；同一综述还给出了对所有充分大的 x，x 以下奇伪素数的界 x/L(x)^(1/2)。<sup>[5](https://math.dartmouth.edu/~carlp/pspssw2.pdf)</sup>

## References

1. [A001567: Fermat pseudoprimes to base 2, OEIS](https://oeis.org/A001567)
2. [Primality Proving 2.2: Fermat, probable-primality and pseudoprimes, The Prime Pages](https://t5k.org/prove/prove2_2.html)
3. [Fermat Pseudoprime, Wolfram MathWorld](https://mathworld.wolfram.com/FermatPseudoprime.html)
4. [Pomerance, Selfridge, Wagstaff (1980). The Pseudoprimes to 25·10^9. Mathematics of Computation.](https://www.ams.org/journals/mcom/1980-35-151/S0025-5718-1980-0572872-7/S0025-5718-1980-0572872-7.pdf)
5. [Pomerance, Carl. Pseudoprimes (survey paper)](https://math.dartmouth.edu/~carlp/pspssw2.pdf)
6. [Pseudoprime Statistics and Tables, ntheory.org](https://ntheory.org/pseudoprimes.html)
7. [Tables of pseudoprimes and related data, CECM, Simon Fraser University](https://www.cecm.sfu.ca/Pseudoprimes/)
8. [Prime Testing Algorithm, GNU MP 6.3.0 manual](https://gmplib.org/manual/Prime-Testing-Algorithm)
9. [Probably Primes, NTIC Primes open textbook](https://math.gordon.edu/ntic/ntic2021-7/section-probable-primes.html)
10. [Primality Testing and Integer Factorization, chapter 12](https://www.math.auckland.ac.nz/~sgal018/crypto-book/ch12.pdf)
11. [Bad witnesses for a composite number, Acta Arithmetica](https://doi.org/10.4064/aa230512-17-2)
12. [Fermat's Little Theorem, Wolfram MathWorld](https://mathworld.wolfram.com/FermatsLittleTheorem.html)
13. [Advances in tabulating Carmichael numbers, Research in Number Theory (2024)](https://link.springer.com/article/10.1007/s40993-024-00598-3)
14. [Probabilistic Primality Testing, Isabelle Archive of Formal Proofs](https://isa-afp.org/browser_info/current/AFP/Probabilistic_Prime_Tests/outline.pdf)
15. [Erdős, Paul (1956). On pseudoprimes and Carmichael numbers](https://www.renyi.hu/~p_erdos/1956-10.pdf)
16. [Pinch, R. The Carmichael numbers up to 10^16](https://ar5iv.labs.arxiv.org/html/math/9803082)
17. [A table of pseudoprime counts and related data, arXiv 2006.14425](https://arxiv.org/pdf/2006.14425v2.pdf)
18. [Pseudo-prime, Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Pseudo-prime)
19. [MIT 18.783 Lecture Notes 11: Primality proving (2025)](https://math.mit.edu/classes/18.783/2025/LectureNotes11.pdf)
20. [On the Asymptotic Density of Fermat Pseudoprimes to a Fixed Base, American Mathematical Monthly (2026)](https://www.tandfonline.com/doi/full/10.1080/00029890.2026.2722582)
21. [Carmichael Number -- from Wolfram MathWorld](https://mathworld.wolfram.com/CarmichaelNumber.html)
22. [math.dartmouth.edu](https://math.dartmouth.edu/~carlp/evenpsps032725.pdf)
23. [Rabin-Miller Strong Pseudoprime Test -- from Wolfram MathWorld](https://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html)
24. [Number Theory - Primality Tests](https://crypto.stanford.edu/pbc/notes/numbertheory/millerrabin.html)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Computational and probabilistic number theory › Primality testing algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/fermat-pseudoprime

English original: https://www.edgepedia.org/fermat-pseudoprime
