# AKS素性测试

AKS素性测试是一种确定性、无条件、多项式时间的算法，用于判定输入的整数是素数还是合数。该算法由坎普尔印度理工学院（Indian Institute of Technology at Kanpur）的马宁德拉·阿格拉沃尔（Manindra Agrawal）、尼拉杰·卡亚尔（Neeraj Kayal）和尼廷·萨克塞纳（Nitin Saxena）于2002年8月宣布，并以《素数属于P》（"PRIMES is in P"）为题发表于《数学年刊》（*Annals of Mathematics*）160(2), 781–793 (2004)<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>。它是首个同时具备确定性、一般性、无条件性和多项式时间的算法；此前所有已知的多项式时间素性测试要么是概率性的，要么依赖于一个未经证明的假设——广义黎曼猜想（generalized Riemann Hypothesis）<sup>[2](https://www.sigact.org/prizes/g%C3%B6del/2006.html)</sup><sup> • </sup><sup>[3](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)</sup>。该论文于2002年8月6日出现在坎普尔印度理工学院的网站上，数小时内便在互联网上流传开来，并于8月8日被《纽约时报》（*The New York Times*）报道，称其解决了一个长期悬而未决的问题<sup>[4](https://link.springer.com/book/10.1007/b12334)</sup><sup> • </sup><sup>[2](https://www.sigact.org/prizes/g%C3%B6del/2006.html)</sup><sup> • </sup><sup>[5](https://www.nytimes.com/2002/08/08/us/new-method-said-to-solve-key-problem-in-math.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 成果 | 首个确定性、无条件、多项式时间的素性测试；《素数属于P》，《数学年刊》160(2), 781–793 (2004)<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup> |
| 核心检验 | 对 a = 1 到 ⌊√φ(r)·log n⌋，检验 (X + a)^n ≡ X^n + a (mod X^r − 1, n)，其中 r 的选取使得 n 模 r 的阶超过 log² n<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup> |
| 原始运行时间 | 2002年预印本中为 Õ((log n)^12)；发表版分析中为 Õ(log^(15/2) n)<sup>[6](http://cr.yp.to/bib/2002/agrawal.pdf)</sup><sup> • </sup><sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup> |
| 已证明的最佳变体 | 伦斯特拉–波梅兰斯修改版，可证明为 Õ(log⁶ n)<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup> |
| 实用状况 | 对于密码学规模的数而言过于缓慢；Õ(de log n) 比特的空间是主要障碍，而非时间<sup>[3](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)</sup><sup> • </sup><sup>[7](https://eprint.iacr.org/2026/051)</sup> |
| 荣誉 | 2006年哥德尔奖授予阿格拉沃尔、卡亚尔和萨克塞纳<sup>[2](https://www.sigact.org/prizes/g%C3%B6del/2006.html)</sup> |
| 最大规模的认证 | 布伦特（Brent）用确定性AKS在32小时内证明了 10^49 + 9 是素数；伯恩斯坦（Bernstein）用一种随机的AKS类算法在13小时内证明了 2^1024 + 643 是素数<sup>[7](https://eprint.iacr.org/2026/051)</sup> |

## 2002年之前的素性测试

寻找一种确定性、无误差且多项式时间的算法，数十年来一直是复杂性理论中一个著名的未解问题<sup>[4](https://link.springer.com/book/10.1007/b12334)</sup>。正如原始预印本所定位的那样，2002年之前的图景如下：米勒（Miller，1976）在假定广义黎曼猜想的前提下给出了一种确定性多项式时间测试；拉宾（Rabin，1980）将其修改为一种无条件但随机化的测试；索洛韦–施特拉森（Solovay–Strassen，1977）给出了另一种随机化测试；阿德尔曼–波梅兰斯–鲁梅利（Adleman–Pomerance–Rumely，1983）实现了确定性 (log n)^O(log log log n) 时间；戈德瓦塞尔–基利安（Goldwasser–Kilian，1986）和阿德尔曼–黄（Adleman–Huang，1992）给出了随机化的椭圆曲线证书算法<sup>[6](http://cr.yp.to/bib/2002/agrawal.pdf)</sup>。

在实践中，AKS之前的素性证明依赖于两大类别。分圆素性测试（cyclotomic primality test，APR-CL）是确定性的，能证明素性或合数性，但不在多项式时间内运行，尽管非常接近；椭圆曲线素性测试（elliptic-curve primality test，ECPP）提供证明但不是确定性的。使用其中任何一种，数千位十进制数字的数的素性早已可以被常规地证明<sup>[8](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/05rene.pdf)</sup>。对于快速筛选，随机化测试占主导地位：对于一个奇合数 n，1 到 n−1 之间的底数 a 中至少有 75% 是米勒–拉宾见证数，因此对于一个固定的奇合数，50 次独立运行全部无法得出结论的概率至多为 (25%)^50 ≈ 10^−31<sup>[3](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)</sup>。

## 算法

已发表的算法分为若干步骤，所有步骤的界都是 log n 的多项式<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>：

1. 检查 n 是否为完全幂；若是，则 n 为合数。
2. 找到最小的 r，使得 n 模 r 的乘法阶（记作 or(n)）超过 log² n。
3. 对 a 不超过 r 的情况检查 gcd(a, n)；任何大于 1 的公因子都证明 n 为合数。
4. 对 a = 1 到 ⌊√φ(r)·log n⌋ 检验同余式 (X + a)^n ≡ X^n + a (mod X^r − 1, n)。若任一检验失败，则 n 为合数；若全部通过，则 n 是素数幂，从而是素数。

一种现代的圆整参数表述将同样的结构明确呈现出来：找到最小的 r ≥ 2，满足 gcd(N, r) = 1 且 ord_r(N) > n²，其中 n = ⌊log N⌋ + 1，然后在商环中对 1 ≤ a ≤ ⌈n√r⌉ 检验 (X + a)^N = X^N + a；对于 N ≥ 3，搜索终止时 r ≤ 2n⁵。检查阶不需要对 r 进行因式分解：计算 N, N², …, N^(n²) mod r，并验证其中没有一个等于 1<sup>[9](https://www.cs.purdue.edu/homes/hmaji/teaching/Fall%202026/lectures/gptaks.pdf)</sup>。

## 工作原理

该检验是有限域上费马小定理的多项式推广。在整数中，费马定理的逆命题不成立，而且对于卡迈克尔数（Carmichael numbers）——即对所有与 n 互素的 a 都满足 a^n ≡ a (mod n) 的合数——失败得尤为显著<sup>[6](http://cr.yp.to/bib/2002/agrawal.pdf)</sup>。在模 X^r − 1 和 n 的多项式环中运算改变了这一点：所有素数 n 对每个 a 和 r 都满足该同余式，而对于一个选取使得 n 模 r 的阶足够大的 r，如果该同余式对足够多的 a 值成立，那么 n 必定是素数幂<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>。

阶条件是使少量见证数足够的原因。在AKS定理中，n 使用一个与 n 互素的整数 q 来检验，其中 n 模 q 的乘法阶超过 (log₂ n)²；检验随即在 Õ(q^(3/2)(log n)³) 时间内运行<sup>[10](https://math.dartmouth.edu/~carlp/PDF/complexity12.pdf)</sup>。正确性证明除了一个关于满足 p − 1 有大素因子的素数 p 的密度的筛法理论结果外，只需要简单的代数<sup>[6](http://cr.yp.to/bib/2002/agrawal.pdf)</sup>。其核心论证以两种方式对同一个有限群进行计数，表明合数 n 不可能对所有所需的 a 值满足压缩多项式费马恒等式<sup>[9](https://www.cs.purdue.edu/homes/hmaji/teaching/Fall%202026/lectures/gptaks.pdf)</sup>。

## 运行时间与改进

运行时间的历史是一系列不断缩小的指数：

- 最初的2002年预印本提出了一个在 Õ((log n)^12) 时间内运行的确定性算法，并指出一个关于索菲·热尔曼素数（Sophie Germain primes，即满足 2p + 1 也是素数的素数 p）分布的广泛相信的猜想会将运行时间降至 Õ((log n)^6) 步<sup>[6](http://cr.yp.to/bib/2002/agrawal.pdf)</sup>。
- 发表的《数学年刊》版本为以幂运算为主的步骤推导出 Õ(log^(21/2) n)，并利用一个关于满足 q − 1 有大素因子的素数 q 的密度引理（已知对不超过 0.6683 的指数成立），证明了渐近时间复杂度 Õ(log^(15/2) n)<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>。
- 一个完全初等的界给出 q = O((log n)^5)，导致 Õ((log n)^10.5)；使用富夫里（Fouvry）定理给出 q = O((log n)^3)，导致 Õ((log n)^7.5)<sup>[10](https://math.dartmouth.edu/~carlp/PDF/complexity12.pdf)</sup>。富夫里定理依赖于西格尔（Siegel）定理，因此若不朝着广义黎曼猜想取得突破，该界中的常数无法在数值上变得有效；对于大多数数，存在大小为 O((log n)²) 的有效 q，给出 Õ((log n)^6)<sup>[10](https://math.dartmouth.edu/~carlp/PDF/complexity12.pdf)</sup>。
- 亨德里克·伦斯特拉（Hendrik Lenstra）和卡尔·波梅兰斯（Carl Pomerance）制作了该算法的一个修改版，其时间复杂度可证明为 Õ(log⁶ n)<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>。他们的高斯周期方法将模多项式的选择从分圆多项式替换为任意一个次数 d > (log₂ n)² 且行为适当的首一整系数多项式<sup>[10](https://math.dartmouth.edu/~carlp/PDF/complexity12.pdf)</sup>。

原论文中的一个界后来被更正。2019年的一则勘误指出引理4.3的证明有误，致谢匿名审稿人以及 [CS05]、[RG05] 和 [Rui18]，并给出了一个更正后的证明，表明存在 r ≤ max{3, ⌈log⁵ n⌉} 使得 or(n) > log² n<sup>[11](https://annals.math.princeton.edu/wp-content/uploads/annals-v189-n1-p06-s.pdf)</sup>。

猜想中的终点仍然悬而未决。原论文的启发式 Õ(log⁶ n) 建立在一个索菲·热尔曼/阿廷型密度猜想之上，若能实现 r = O(log² n)，该猜想便随之成立<sup>[1](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)</sup>；一篇2024年的预印本报告了一个归于阿格拉沃尔的猜想，若其为真，将把AKS的多项式次数从12降至3<sup>[12](https://eprint.iacr.org/2024/121.pdf)</sup>。这两个猜想性目标在此作为文献中各自独立的论断来报告，而非作为一个已有定论的问题。

## 数据一览

实际的AKS认证说明了多项式时间与实际速度之间的差距。使用模多项式 x^e − 1 的确定性AKS算法，理查德·布伦特（Richard Brent）以 (e = 491, s = 28801) 在32小时内测试了 n = 10^49 + 9，并以 (e = 3541, s = 58820) 在估计1年内测试了 n = 10^100 + 267；伯恩斯坦曾用他改进的随机AKS类算法在一台800 MHz的PC上于13小时内证明了 2^1024 + 643 是素数<sup>[7](https://eprint.iacr.org/2026/051)</sup>。

AKS类算法的主要实际问题不在于时间，而在于所需的 Õ(de log n) 比特空间；阿万齐（Avanzi）和米哈伊莱斯库（Mihailescu）表明 d = 60 足以测试所有41000位十进制数字的数<sup>[7](https://eprint.iacr.org/2026/051)</sup>。一篇2024年的预印本通过对单个 a 值检验最后阶段的模方程并任意减小 r 来加速AKS，展示了1031位循环单位数（repunit-1031）的素性在12秒内得到证明，指数为2203的梅森数（Mersenne-2203，969位十进制数字）的素性在约半秒内得到证明，并用约12秒表明1021位循环单位数是合数；该修改算法不附带正确性保证，尽管其作者报告从未发现它给出错误结果<sup>[12](https://eprint.iacr.org/2024/121.pdf)</sup>。

## 与其他素性测试的比较

AKS在设计空间中占据一个独特的位置：确定性、一般性、无条件且多项式时间，但“多项式时间”并不等同于在实践中快速，而且对于密码系统中所需的大数而言，AKS过于缓慢<sup>[3](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)</sup>。

- **米勒–拉宾**是随机化的且快速。对于一个奇合数，至少有75%的底数是见证数，50次独立运行使一个固定的奇合数通过所有测试的概率至多为 10^−31，因此少数几次运行就使与确定性测试之间的差别在实际中几乎可以忽略<sup>[3](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)</sup>。在关于二次狄利克雷特征的广义黎曼猜想下，米勒–拉宾可以转化为一种确定性多项式时间测试，即米勒1976年的结果；对于大多数合数 n，通过的概率远小于 1/4，因此通过少数几次测试就足以让实践者信服<sup>[8](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/05rene.pdf)</sup>。
- **贝利–PSW（Baillie–PSW）**发展于20世纪80年代，在检查1000以下的小素因子之后，将以2为底的米勒–拉宾测试与卢卡斯序列测试相结合；从未有小于 2^64 的合数通过该测试，且尚未发现BPSW伪素数<sup>[13](https://arxiv.org/html/2006.08444)</sup>。
- **ECPP**在随机启发式时间 Õ(log⁶ n)（使用快速乘法时为 Õ(log⁵ n)）内运行，并生成易于验证的证书；在实践中它比AKS表现好得多，已被用于证明高达数千位十进制数字的数的素性<sup>[14](https://ar5iv.labs.arxiv.org/html/math/0301179)</sup>。
- **APR-CL**，即分圆测试，是确定性的且接近多项式时间，但不是多项式时间<sup>[8](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/05rene.pdf)</sup>。

在斯胡夫（Schoof）的调查发表时，AKS或其更高效的概率版本尚未被广泛实现，因此实践中的素性证明仍然依赖于较旧的测试<sup>[8](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/05rene.pdf)</sup>。2024年的加速变体虽然在实用上有价值，但仍比广泛使用的米勒–拉宾–塞尔弗里奇–莫尼耶（Miller–Rabin–Selfridge–Monier）和索洛韦–施特拉森算法慢得多<sup>[12](https://eprint.iacr.org/2024/121.pdf)</sup>。

## 反响、变体与遗产

2006年理论计算机科学杰出论文哥德尔奖授予马宁德拉·阿格拉沃尔、尼拉杰·卡亚尔和尼廷·萨克塞纳，以表彰《素数属于P》<sup>[2](https://www.sigact.org/prizes/g%C3%B6del/2006.html)</sup>。该论文建立在阿格拉沃尔和索梅纳特·比斯瓦斯（Somenath Biswas）在FOCS 1999上提出的一个概率算法之上，三位作者将其去随机化<sup>[2](https://www.sigact.org/prizes/g%C3%B6del/2006.html)</sup>。这一发现源于坎普尔印度理工学院的学生工作：本科生拉贾特·巴塔查里亚（Rajat Bhattacharya）在一亿以内的所有数上测试了AKS判据，发现满足该条件的合数只在2到100范围内的极少数 r 值上成立；卡亚尔和萨克塞纳于2001年8月在阿格拉沃尔指导下开始他们的BTech项目，将实验扩展到 10^10，于2002年4月底完成项目，并获得了该系的最佳BTech项目奖<sup>[15](https://www.cse.iitk.ac.in/users/sb/papers/storyf.pdf)</sup>。

当时的反应强调了该方法的简洁性。P. 莱兰（P. Leyland）评论说，该算法“以一种极其简洁的方式”解决了一个长期存在的问题，数学界不禁想知道还有哪些类似的问题被同样忽视了<sup>[16](https://mathworld.wolfram.com/AKSPrimalityTest.html)</sup>。伯恩斯坦2004年的综述列出了一个使用高斯周期的伦斯特拉–波梅兰斯变体，它对每个素数都能证明素性，验证时间为 n^(lg n)^(6+o(1))；以及费马型测试，它对每个合数都能证明合数性，验证时间至多为 n^(lg n)^(4+o(1))<sup>[17](https://cr.yp.to/primetests/prime2004-20040212.pdf)</sup>。后来的工作改进了 r 的选取步骤：一篇2026年的预印本给出了一个确定性 O(D^(1/2+o(1))) 算法，它要么在 ℤ_N* 中找到一个阶大于 D 的元素，要么返回 N 的一个非平凡因子，要么报告 N 为素数，哈维（Harvey）和希特迈尔（Hittmeir）独立获得了类似结果<sup>[18](https://arxiv.org/html/2605.09592v1)</sup>。

在复杂性理论中，该结果被解读为一个可行性陈述：对应于AKS的包含关系被解释为“素性是一个可行性质”<sup>[19](https://www.cambridge.org/core/journals/forum-of-mathematics-sigma/article/feasibility-of-primality-in-bounded-arithmetic/18A1BD004161C115D21E117A20B0B172)</sup>。

## References

1. [Agrawal, Kayal, Saxena (2004). PRIMES is in P. Annals of Mathematics 160(2), 781–793.](https://annals.math.princeton.edu/wp-content/uploads/annals-v160-n2-p12.pdf)
2. [2006 Gödel Prize citation, ACM SIGACT.](https://www.sigact.org/prizes/g%C3%B6del/2006.html)
3. [Worthington (2018). Primality Testing, Whitman College thesis.](https://www.whitman.edu/documents/Academics/Mathematics/2018/Worthington.pdf)
4. [Dietzfelbinger. Primality Testing in Polynomial Time, Springer Lecture Notes.](https://link.springer.com/book/10.1007/b12334)
5. [New Method Said to Solve Key Problem In Math, The New York Times, August 8, 2002.](https://www.nytimes.com/2002/08/08/us/new-method-said-to-solve-key-problem-in-math.html)
6. [Agrawal, Kayal, Saxena (2002). PRIMES is in P (original preprint).](http://cr.yp.to/bib/2002/agrawal.pdf)
7. [An improved random AKS-class primality proving algorithm, IACR ePrint 2026/051.](https://eprint.iacr.org/2026/051)
8. [René Schoof. Four primality testing algorithms.](https://pub.math.leidenuniv.nl/~stevenhagenp/ANTproc/05rene.pdf)
9. [AKS primality testing: The algorithm, then the proof, Purdue lecture notes.](https://www.cs.purdue.edu/homes/hmaji/teaching/Fall%202026/lectures/gptaks.pdf)
10. [Carl Pomerance. Primality testing with Gaussian periods.](https://math.dartmouth.edu/~carlp/PDF/complexity12.pdf)
11. [Agrawal, Kayal, Saxena (2019). Errata: PRIMES is in P. Annals of Mathematics 189, 317–318.](https://annals.math.princeton.edu/wp-content/uploads/annals-v189-n1-p06-s.pdf)
12. [An acceleration of the AKS prime identification algorithm, IACR ePrint 2024/121.](https://eprint.iacr.org/2024/121.pdf)
13. [Taxonomy and Practical Evaluation of Primality Testing Algorithms, arXiv.](https://arxiv.org/html/2006.08444)
14. [Primality Proving via One Round in ECPP and One Iteration in AKS, arXiv math/0301179.](https://ar5iv.labs.arxiv.org/html/math/0301179)
15. [Story of a Discovery, IIT Kanpur retrospective.](https://www.cse.iitk.ac.in/users/sb/papers/storyf.pdf)
16. [AKS Primality Test, Wolfram MathWorld.](https://mathworld.wolfram.com/AKSPrimalityTest.html)
17. [D. J. Bernstein (2004). Distinguishing prime numbers from composite numbers: the state of the art.](https://cr.yp.to/primetests/prime2004-20040212.pdf)
18. [Deterministically finding an element of large order in ℤ_N*, arXiv 2026.](https://arxiv.org/html/2605.09592v1)
19. [Feasibility of primality in bounded arithmetic, Forum of Mathematics, Sigma.](https://www.cambridge.org/core/journals/forum-of-mathematics-sigma/article/feasibility-of-primality-in-bounded-arithmetic/18A1BD004161C115D21E117A20B0B172)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: 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/aks-primality-test

English original: https://www.edgepedia.org/aks-primality-test
