<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://indianpedia.org/index.php?action=history&amp;feed=atom&amp;title=AKS_primality_test</id>
	<title>AKS primality test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://indianpedia.org/index.php?action=history&amp;feed=atom&amp;title=AKS_primality_test"/>
	<link rel="alternate" type="text/html" href="https://indianpedia.org/index.php?title=AKS_primality_test&amp;action=history"/>
	<updated>2026-07-30T12:58:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.4</generator>
	<entry>
		<id>https://indianpedia.org/index.php?title=AKS_primality_test&amp;diff=483875&amp;oldid=prev</id>
		<title>Mythu09 at 02:27, 27 March 2026</title>
		<link rel="alternate" type="text/html" href="https://indianpedia.org/index.php?title=AKS_primality_test&amp;diff=483875&amp;oldid=prev"/>
		<updated>2026-03-27T02:27:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Algorithm checking for prime numbers}}&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;AKS primality test&amp;#039;&amp;#039;&amp;#039; (also known as the &amp;#039;&amp;#039;&amp;#039;Agrawal–Kayal–Saxena primality test&amp;#039;&amp;#039;&amp;#039; and the &amp;#039;&amp;#039;&amp;#039;cyclotomic AKS test&amp;#039;&amp;#039;&amp;#039;) is a [[deterministic algorithm|deterministic]] [[primality test|primality-proving]] [[algorithm]] created and published by [[Manindra Agrawal]], [[Neeraj Kayal]], and [[Nitin Saxena]], computer scientists at the [[Indian Institute of Technology Kanpur]], on August 6, 2002, in an article titled &amp;quot;PRIMES is in P&amp;quot;.&amp;lt;ref name=&amp;quot;AKS&amp;quot;&amp;gt;{{cite journal |first1=Manindra |last1=Agrawal |first2=Neeraj |last2=Kayal |first3=Nitin |last3=Saxena |url=http://www.cse.iitk.ac.in/users/manindra/algebra/primality_v6.pdf |title=PRIMES is in P |journal=[[Annals of Mathematics]] |volume=160 |year=2004 |issue=2 |pages=781–793 |doi=10.4007/annals.2004.160.781 |jstor=3597229 |doi-access=free }}&amp;lt;/ref&amp;gt; The algorithm was the first one which is able to determine in [[polynomial time]], whether a given number is [[Prime number|prime]] or [[Composite number|composite]] without relying on [[mathematical conjecture]]s such as the [[generalized Riemann hypothesis]]. The proof is also notable for not relying on the field of [[analysis (mathematics)|analysis]].&amp;lt;ref&amp;gt;{{cite journal|first=Andrew|last=Granville|url=https://www.ams.org/bull/2005-42-01/S0273-0979-04-01037-7/home.html|title=It is easy to determine whether a given integer is prime|journal=Bull. Amer. Math. Soc.|volume=42|year=2005|pages=3–38|doi=10.1090/S0273-0979-04-01037-7|doi-access=free}}&amp;lt;/ref&amp;gt; In 2006 the authors received both the [[Gödel Prize]] and [[Fulkerson Prize]] for their work.&lt;br /&gt;
&lt;br /&gt;
==Importance==&lt;br /&gt;
AKS is the first primality-proving algorithm to be simultaneously &amp;#039;&amp;#039;general&amp;#039;&amp;#039;, &amp;#039;&amp;#039;polynomial-time&amp;#039;&amp;#039;, &amp;#039;&amp;#039;deterministic&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;unconditionally correct&amp;#039;&amp;#039;. Previous algorithms had been developed for centuries and achieved three of these properties at most, but not all four. &lt;br /&gt;
* The AKS algorithm can be used to verify the primality of any &amp;#039;&amp;#039;&amp;#039;general&amp;#039;&amp;#039;&amp;#039; number given. Many fast primality tests are known that work only for numbers with certain properties. For example, the [[Lucas–Lehmer primality test|Lucas–Lehmer test]] works only for [[Mersenne number]]s, while [[Pépin&amp;#039;s test]] can be applied to [[Fermat number]]s only.&lt;br /&gt;
* The maximum running time of the algorithm can be bounded by a &amp;#039;&amp;#039;&amp;#039;[[Polynomial time#Polynomial time|polynomial]]&amp;#039;&amp;#039;&amp;#039; over the number of digits in the target number. [[Elliptic curve primality proving|ECPP]] and [[Adleman–Pomerance–Rumely primality test|APR]] conclusively prove or disprove that a given number is prime, but are not known to have polynomial time bounds for all inputs.&lt;br /&gt;
* The algorithm is guaranteed to distinguish &amp;#039;&amp;#039;&amp;#039;[[Deterministic algorithm|deterministically]]&amp;#039;&amp;#039;&amp;#039; whether the target number is prime or composite. Randomized tests, such as [[Miller–Rabin primality test|Miller–Rabin]] and [[Baillie–PSW primality test|Baillie–PSW]], can test any given number for primality in polynomial time, but are known to produce only a probabilistic result.&lt;br /&gt;
* The correctness of AKS is &amp;#039;&amp;#039;&amp;#039;not conditional&amp;#039;&amp;#039;&amp;#039; on any subsidiary unproved [[hypothesis]]. In contrast, Miller&amp;#039;s version of the [[Miller–Rabin primality test#Deterministic variants|Miller–Rabin test]] is fully deterministic and runs in polynomial time over all inputs, but its correctness depends on the truth of the yet-unproved [[generalized Riemann hypothesis]].&lt;br /&gt;
&lt;br /&gt;
While the algorithm is of immense theoretical importance, it is not used in practice, rendering it a [[galactic algorithm]].  For 64-bit inputs, the [[Baillie–PSW primality test|Baillie–PSW test]] is deterministic and runs many orders of magnitude faster.  For larger inputs, the performance of the (also unconditionally correct) ECPP and APR tests is &amp;#039;&amp;#039;far&amp;#039;&amp;#039; superior to AKS.  Additionally, ECPP can output a [[primality certificate]] that allows independent and rapid verification of the results, which is not possible with the AKS algorithm.&lt;br /&gt;
&lt;br /&gt;
==Concepts==&lt;br /&gt;
The AKS primality test is based upon the following theorem: Given an integer &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt; and integer &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; [[coprime]] to &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is prime if and only if the [[polynomial ring|polynomial]] [[Congruence relation#Modular arithmetic|congruence relation]]&lt;br /&gt;
{{NumBlk|:|&amp;lt;math&amp;gt;(X + a)^{n} \equiv X^{n} + a \pmod{n}&amp;lt;/math&amp;gt;|{{EquationRef|1}}}}&lt;br /&gt;
holds within the polynomial ring &amp;lt;math&amp;gt;(\mathbb Z/n\mathbb Z)[X]&amp;lt;/math&amp;gt;.&amp;lt;ref name=&amp;quot;AKS&amp;quot;/&amp;gt; Note that &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; denotes the [[polynomial ring#Definition (univariate case)|indeterminate]] which generates this polynomial ring.&lt;br /&gt;
&lt;br /&gt;
This theorem is a generalization to polynomials of [[Fermat&amp;#039;s little theorem]].  In one direction it can easily be proved using the [[binomial theorem]] together with the following property of the [[binomial coefficient]]:&lt;br /&gt;
:&amp;lt;math&amp;gt;{n \choose k} \equiv 0 \pmod{n}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;0&amp;lt;k&amp;lt;n&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is prime.&lt;br /&gt;
&lt;br /&gt;
While the relation ({{EquationNote|1}}) constitutes a primality test in itself, verifying it takes [[exponential time]]: the [[brute force method|brute force]] approach would require the expansion of the &amp;lt;math&amp;gt; (X + a)^n&amp;lt;/math&amp;gt; polynomial and a reduction &amp;lt;math&amp;gt;\pmod{n}&amp;lt;/math&amp;gt; of the resulting &amp;lt;math&amp;gt;n + 1&amp;lt;/math&amp;gt; coefficients.&lt;br /&gt;
&lt;br /&gt;
The congruence is an equality in the [[polynomial ring]] &amp;lt;math&amp;gt;(\mathbb Z/n\mathbb Z)[X]&amp;lt;/math&amp;gt;. Evaluating in a quotient ring of &amp;lt;math&amp;gt;(\mathbb Z/n\mathbb Z)[X]&amp;lt;/math&amp;gt; creates an upper bound for the degree of the polynomials involved. The AKS evaluates the equality in &amp;lt;math&amp;gt;(\mathbb Z/n\mathbb Z)[X]/(X^r -1)&amp;lt;/math&amp;gt;, making the [[Computational complexity theory|computational complexity]] dependent on the size of &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. For clarity,&amp;lt;ref name=&amp;quot;AKS&amp;quot;/&amp;gt; this is expressed as the congruence&lt;br /&gt;
{{NumBlk|:|&amp;lt;math&amp;gt;(X + a)^{n} \equiv (X^{n} + a) \pmod{X^{r}-1, n}&amp;lt;/math&amp;gt;|{{EquationRef|2}}}}&lt;br /&gt;
which is the same as:&lt;br /&gt;
{{NumBlk|:|&amp;lt;math&amp;gt;(X + a)^n - (X^n + a) = (X^r - 1)g + nf&amp;lt;/math&amp;gt;|{{EquationRef|3}}}}&lt;br /&gt;
for some polynomials &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that all primes satisfy this relation (choosing &amp;lt;math&amp;gt;g=0&amp;lt;/math&amp;gt; in ({{EquationNote|3}}) gives ({{EquationNote|1}}), which holds for &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; prime). This congruence can be checked in polynomial time when &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; is polynomial to the digits of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The AKS algorithm evaluates this congruence for a large set of &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; values, whose size is polynomial to the digits of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The proof of validity of the AKS algorithm shows that one can find an &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; and a set of &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; values with the above properties such that if the congruences hold then &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a power of a prime.&amp;lt;ref name=&amp;quot;AKS&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==History and running time==&lt;br /&gt;
In the first version of the above-cited paper, the authors proved the asymptotic time complexity of the algorithm to be &amp;lt;math&amp;gt;\tilde{O}(\log(n)^{12})&amp;lt;/math&amp;gt; (using [[Big O notation#Extensions to the Bachmann–Landau notations|Õ]] from [[big O notation]])—the twelfth power of the number of digits in &amp;#039;&amp;#039;n&amp;#039;&amp;#039; times a factor that is polylogarithmic in the number of digits. However, this upper bound was rather loose; a widely-held conjecture about the distribution of the [[Sophie Germain prime]]s would, if true, immediately cut the worst case down to &amp;lt;math&amp;gt;\tilde{O}(\log(n)^6)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In the months following the discovery, new variants appeared (Lenstra 2002, Pomerance 2002, Berrizbeitia 2002, Cheng 2003, Bernstein 2003a/b, Lenstra and Pomerance 2003), which improved the speed of computation greatly. Owing to the existence of the many variants, Crandall and Papadopoulos refer to the &amp;quot;AKS-class&amp;quot; of algorithms in their scientific paper &amp;quot;On the implementation of AKS-class primality tests&amp;quot;, published in March 2003.&lt;br /&gt;
&lt;br /&gt;
In response to some of these variants, and to other feedback, the paper &amp;quot;PRIMES is in P&amp;quot; was updated with a new formulation of the AKS algorithm and of its proof of correctness. (This version was eventually published in &amp;#039;&amp;#039;[[Annals of Mathematics]]&amp;#039;&amp;#039;.) While the basic idea remained the same, &amp;#039;&amp;#039;r&amp;#039;&amp;#039; was chosen in a new manner, and the proof of correctness was more coherently organized. The new proof relied almost exclusively on the behavior of [[cyclotomic polynomial]]s over [[finite fields]]. The new upper bound on time complexity was &amp;lt;math&amp;gt;\tilde{O}(\log(n)^{10.5})&amp;lt;/math&amp;gt;, later reduced using additional results from [[sieve theory]] to &amp;lt;math&amp;gt;\tilde{O}(\log(n)^{7.5})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In 2005, [[Carl Pomerance|Pomerance]] and [[Hendrik Lenstra|Lenstra]] demonstrated a variant of AKS that runs in &amp;lt;math&amp;gt;\tilde{O}(\log(n)^{6})&amp;lt;/math&amp;gt; operations,&amp;lt;ref name=&amp;quot;lenstra_pomerance_2005&amp;quot;&amp;gt;H. W. Lenstra Jr. and Carl Pomerance, &amp;quot;[http://www.math.dartmouth.edu/~carlp/PDF/complexity12.pdf Primality testing with Gaussian periods]&amp;quot;, preliminary version July 20, 2005.&amp;lt;/ref&amp;gt; leading to another updated version of the paper.&amp;lt;ref name=&amp;quot;lenstra_pomerance_2011&amp;quot;&amp;gt;H. W. Lenstra Jr. and Carl Pomerance, &amp;quot;[http://www.math.dartmouth.edu/~carlp/aks041411.pdf Primality testing with Gaussian periods] {{Webarchive|url=https://web.archive.org/web/20120225052810/http://www.math.dartmouth.edu/~carlp/aks041411.pdf |date=2012-02-25 }}&amp;quot;, version of April 12, 2011.&amp;lt;/ref&amp;gt; Agrawal, Kayal and Saxena proposed a variant which would run in &amp;lt;math&amp;gt;\tilde{O}(\log(n)^{3})&amp;lt;/math&amp;gt; if [[Agrawal&amp;#039;s conjecture]] were true; however, a heuristic argument by Pomerance and Lenstra suggested that it is probably false.&lt;br /&gt;
&lt;br /&gt;
==The algorithm==&lt;br /&gt;
The algorithm is as follows:&amp;lt;ref name=&amp;quot;AKS&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: Input: integer {{math|&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;amp;nbsp;&amp;gt;&amp;amp;nbsp;1}}.&lt;br /&gt;
# Check if &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is a [[perfect power]]: if {{math|1=&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;b&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt;}} for integers {{math|&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;amp;nbsp;&amp;gt;&amp;amp;nbsp;1}} and {{math|&amp;#039;&amp;#039;b&amp;#039;&amp;#039;&amp;amp;nbsp;&amp;gt;&amp;amp;nbsp;1}}, then output &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;.&lt;br /&gt;
# Find the smallest &amp;#039;&amp;#039;r&amp;#039;&amp;#039; such that {{math|[[multiplicative order|ord]]&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;)&amp;amp;nbsp;&amp;gt;&amp;amp;nbsp;(log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; &amp;#039;&amp;#039;n&amp;#039;&amp;#039;)&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;}}.  If &amp;#039;&amp;#039;r&amp;#039;&amp;#039; and &amp;#039;&amp;#039;n&amp;#039;&amp;#039; are not coprime, then output &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;.&lt;br /&gt;
# For all 2 ≤ &amp;#039;&amp;#039;a&amp;#039;&amp;#039; ≤ min (&amp;#039;&amp;#039;r&amp;#039;&amp;#039;, &amp;#039;&amp;#039;n&amp;#039;&amp;#039;−1), check that &amp;#039;&amp;#039;a&amp;#039;&amp;#039; does not divide &amp;#039;&amp;#039;n&amp;#039;&amp;#039;: If &amp;#039;&amp;#039;a&amp;#039;&amp;#039;|&amp;#039;&amp;#039;n&amp;#039;&amp;#039; for some 2 ≤ &amp;#039;&amp;#039;a&amp;#039;&amp;#039; ≤ min (&amp;#039;&amp;#039;r&amp;#039;&amp;#039;, &amp;#039;&amp;#039;n&amp;#039;&amp;#039;−1), then output &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;.&lt;br /&gt;
# If &amp;#039;&amp;#039;n&amp;#039;&amp;#039; ≤ &amp;#039;&amp;#039;r&amp;#039;&amp;#039;, then output &amp;#039;&amp;#039;prime&amp;#039;&amp;#039;.&lt;br /&gt;
# For {{math|1=&amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;1}} to &amp;lt;math&amp;gt;\left\lfloor \sqrt{\varphi(r)}\log_2(n) \right\rfloor&amp;lt;/math&amp;gt; do&lt;br /&gt;
#: if (&amp;#039;&amp;#039;X&amp;#039;&amp;#039;+&amp;#039;&amp;#039;a&amp;#039;&amp;#039;)&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; ≠ &amp;#039;&amp;#039;X&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt;+&amp;#039;&amp;#039;a&amp;#039;&amp;#039; (mod &amp;#039;&amp;#039;X&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; − 1,&amp;#039;&amp;#039;n&amp;#039;&amp;#039;), then output &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;;&lt;br /&gt;
# Output &amp;#039;&amp;#039;prime&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Here [[multiplicative order|ord]]&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) is the [[multiplicative order]] of &amp;#039;&amp;#039;n&amp;#039;&amp;#039; [[modular arithmetic|modulo]] &amp;#039;&amp;#039;r&amp;#039;&amp;#039;, log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; is the [[binary logarithm]], and &amp;lt;math&amp;gt;\varphi(r)&amp;lt;/math&amp;gt; is [[Euler&amp;#039;s totient function]] of &amp;#039;&amp;#039;r&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Step 3 is shown in the paper as checking 1 &amp;lt; gcd(&amp;#039;&amp;#039;a&amp;#039;&amp;#039;,&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) &amp;lt; &amp;#039;&amp;#039;n&amp;#039;&amp;#039; for all &amp;#039;&amp;#039;a&amp;#039;&amp;#039; ≤ &amp;#039;&amp;#039;r&amp;#039;&amp;#039;.  It can be seen this is equivalent to trial division up to &amp;#039;&amp;#039;r&amp;#039;&amp;#039;, which can be done very efficiently without using [[greatest common divisor|gcd]].  Similarly the comparison in step 4 can be replaced by having the trial division return &amp;#039;&amp;#039;prime&amp;#039;&amp;#039; once it has checked all values up to and including &amp;lt;math&amp;gt;\left\lfloor \sqrt{n} \right\rfloor.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once beyond very small inputs, step 5 dominates the time taken.  The essential reduction in complexity (from exponential to polynomial) is achieved by performing all calculations in the finite ring&lt;br /&gt;
: &amp;lt;math&amp;gt;R = (\mathbb Z/n\mathbb Z)[X]/(X^r -1)&amp;lt;/math&amp;gt;&lt;br /&gt;
consisting of &amp;lt;math&amp;gt;n^r&amp;lt;/math&amp;gt; elements. This ring contains only the &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; [[monomial]]s &amp;lt;math&amp;gt;\{X^0,X^1,\ldots,X^{r-1}\} &amp;lt;/math&amp;gt;, and the [[coefficient]]s are in &amp;lt;math&amp;gt;\mathbb Z/n\mathbb Z&amp;lt;/math&amp;gt; which has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; elements, all of them codable within &amp;lt;math&amp;gt;\log_2(n)&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
&lt;br /&gt;
Most later improvements made to the algorithm have concentrated on reducing the size of &amp;#039;&amp;#039;r,&amp;#039;&amp;#039; which makes the core operation in step 5 faster, and in reducing the size of &amp;#039;&amp;#039;s&amp;#039;&amp;#039;, the number of loops performed in step 5.&amp;lt;ref name=&amp;quot;bernstein03&amp;quot;&amp;gt;Daniel J. Bernstein, &amp;quot;[https://cr.yp.to/papers/aks.pdf Proving Primality After Agrawal-Kayal-Saxena]&amp;quot;, version of January 25, 2003.&amp;lt;/ref&amp;gt;  Typically these changes do not change the computational complexity, but can lead to many orders of magnitude less time taken; for example, Bernstein&amp;#039;s final version has a theoretical speedup by a factor of over 2 million.&lt;br /&gt;
&lt;br /&gt;
===Proof of validity outline===&lt;br /&gt;
For the algorithm to be correct, all steps that identify &amp;#039;&amp;#039;n&amp;#039;&amp;#039; must be correct. Steps 1, 3, and 4 are trivially correct, since they are based on direct tests of the divisibility of &amp;#039;&amp;#039;n&amp;#039;&amp;#039;. Step 5 is also correct: since (2) is true for any choice of &amp;#039;&amp;#039;a&amp;#039;&amp;#039; coprime to &amp;#039;&amp;#039;n&amp;#039;&amp;#039; and &amp;#039;&amp;#039;r&amp;#039;&amp;#039; if &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is prime, an inequality means that &amp;#039;&amp;#039;n&amp;#039;&amp;#039; must be composite.&lt;br /&gt;
&lt;br /&gt;
The difficult part of the proof is showing that step 6 is true. Its proof of correctness is based on the upper and lower bounds of a [[multiplicative group]] in &amp;lt;math&amp;gt;\mathbb{Z}_{n}[x]&amp;lt;/math&amp;gt; constructed from the (&amp;#039;&amp;#039;X&amp;#039;&amp;#039; + &amp;#039;&amp;#039;a&amp;#039;&amp;#039;) binomials that are tested in step 5. Step 4 guarantees that these binomials are &amp;lt;math&amp;gt;\left\lfloor \sqrt{\varphi(r)}\log_2(n) \right\rfloor&amp;lt;/math&amp;gt; distinct elements of &amp;lt;math&amp;gt;\mathbb{Z}_n[x]&amp;lt;/math&amp;gt;. For the particular choice of &amp;#039;&amp;#039;r&amp;#039;&amp;#039;, the bounds produce a [[proof by contradiction|contradiction]] unless &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is prime or a power of a prime. Together with the test of step 1, this implies that &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is always prime at step 6.&amp;lt;ref name=&amp;quot;AKS&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 1: &amp;#039;&amp;#039;n&amp;#039;&amp;#039; = 31 is prime===&lt;br /&gt;
&lt;br /&gt;
{{pre|style=white-space:pre;overflow:auto;&lt;br /&gt;
|1=&amp;lt;nowiki/&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;Input&amp;#039;&amp;#039;&amp;#039;: integer &amp;#039;&amp;#039;n&amp;#039;&amp;#039; = 31 &amp;gt; 1.&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 1 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;n&amp;#039;&amp;#039; = &amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;b&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; for integers &amp;#039;&amp;#039;a&amp;#039;&amp;#039; &amp;gt; 1 and &amp;#039;&amp;#039;b&amp;#039;&amp;#039; &amp;gt; 1), &lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;.&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; ( b = 2; b &amp;lt;= log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;(n); b++) {&lt;br /&gt;
       a = n&amp;lt;sup&amp;gt;1/b&amp;lt;/sup&amp;gt;;&lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (a is integer), &lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;Return&amp;#039;&amp;#039;&amp;#039;[Composite]&lt;br /&gt;
     }&lt;br /&gt;
     a = n&amp;lt;sup&amp;gt;1/2&amp;lt;/sup&amp;gt;...n&amp;lt;sup&amp;gt;1/4&amp;lt;/sup&amp;gt; = {5.568, 3.141, 2.360}&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 2 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   Find the smallest &amp;#039;&amp;#039;r&amp;#039;&amp;#039; such that &amp;#039;&amp;#039;O&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) &amp;gt; (log&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;2&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; &amp;#039;&amp;#039;n&amp;#039;&amp;#039;)&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
     maxk = ⌊(log&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;2&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; n)&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;⌋;&lt;br /&gt;
     maxr = Max[3, ⌈(Log&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;2&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; n)&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;⌉]; &amp;lt;u&amp;gt;(* maxr really isn&amp;#039;t needed *)&amp;lt;/u&amp;gt;&lt;br /&gt;
     nextR = True;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; (r = 2; nextR &amp;amp;&amp;amp; r &amp;lt; maxr; r++) {&lt;br /&gt;
       nextR = False;&lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; (k = 1; (!nextR) &amp;amp;&amp;amp; k &amp;amp;le; maxk; k++) {&lt;br /&gt;
         nextR = (Mod[n&amp;lt;sup&amp;gt;k&amp;lt;/sup&amp;gt;, r] == 1 {{!!}} Mod[n&amp;lt;sup&amp;gt;k&amp;lt;/sup&amp;gt;, r]==0)&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     r--; &amp;lt;u&amp;gt;(*the loop over increments by one*)&amp;lt;/u&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     r = 29&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 3 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (1 &amp;lt; [[greatest common divisor|gcd]](&amp;#039;&amp;#039;a&amp;#039;&amp;#039;,&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) &amp;lt; &amp;#039;&amp;#039;n&amp;#039;&amp;#039; for some &amp;#039;&amp;#039;a&amp;#039;&amp;#039; ≤ &amp;#039;&amp;#039;r&amp;#039;&amp;#039;), &lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;.&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; (a = r; a &amp;amp;gt; 1; a--) {&lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; ((gcd = GCD[a,n]) &amp;amp;gt; 1 &amp;amp;&amp;amp; gcd &amp;lt; n), &lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;Return&amp;#039;&amp;#039;&amp;#039;[Composite]&lt;br /&gt;
     }&lt;br /&gt;
      &lt;br /&gt;
     gcd = {GCD(29,31)=1, GCD(28,31)=1, ..., GCD(2,31)=1} ≯ 1&lt;br /&gt;
&lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 4 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;n&amp;#039;&amp;#039; ≤ &amp;#039;&amp;#039;r&amp;#039;&amp;#039;), &lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;prime&amp;#039;&amp;#039;.&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (n &amp;amp;le; r), &lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;Return&amp;#039;&amp;#039;&amp;#039;[Prime] &amp;lt;u&amp;gt;(* this step may be omitted if n &amp;amp;gt; 5690034 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     31 &amp;amp;gt; 29&lt;br /&gt;
   &lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 5 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;a&amp;#039;&amp;#039; = 1 &amp;#039;&amp;#039;&amp;#039;to&amp;#039;&amp;#039;&amp;#039; &amp;lt;math&amp;gt;\left\lfloor\sqrt{\varphi(r)}\log_2(n)\right\rfloor&amp;lt;/math&amp;gt; &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; ((&amp;#039;&amp;#039;X&amp;#039;&amp;#039;+&amp;#039;&amp;#039;a&amp;#039;&amp;#039;)&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; ≠ &amp;#039;&amp;#039;X&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; + &amp;#039;&amp;#039;a&amp;#039;&amp;#039; (mod &amp;#039;&amp;#039;X&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;r&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; − 1,&amp;#039;&amp;#039;n&amp;#039;&amp;#039;)), &lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;;&lt;br /&gt;
      &lt;br /&gt;
     φ[x_] := EulerPhi[x];&lt;br /&gt;
     PolyModulo[f_] := PolynomialMod&amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;[[polynomial remainder|PolynomialRemainder]][f, x&amp;lt;sup&amp;gt;r&amp;lt;/sup&amp;gt;-1, x], n&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;;&lt;br /&gt;
     max = Floor[Log[2, n]{{sqrt|φ[r]}}];&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;For&amp;#039;&amp;#039;&amp;#039; (a = 1; a ≤ max; a++) {&lt;br /&gt;
       &amp;#039;&amp;#039;&amp;#039;If&amp;#039;&amp;#039;&amp;#039; (PolyModulo[(x+a)&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; - PolynomialRemainder[x&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt;+a, x&amp;lt;sup&amp;gt;r&amp;lt;/sup&amp;gt;-1, x&amp;lt;nowiki&amp;gt;]]&amp;lt;/nowiki&amp;gt; ≠ 0) {&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;Return&amp;#039;&amp;#039;&amp;#039;[Composite]&lt;br /&gt;
       {&lt;br /&gt;
     }&lt;br /&gt;
      &lt;br /&gt;
     (x+a)&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt; =&lt;br /&gt;
       a&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt; +31a&amp;lt;sup&amp;gt;30&amp;lt;/sup&amp;gt;x +465a&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; +4495a&amp;lt;sup&amp;gt;28&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; +31465a&amp;lt;sup&amp;gt;27&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; +169911a&amp;lt;sup&amp;gt;26&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt; +736281a&amp;lt;sup&amp;gt;25&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt; +2629575a&amp;lt;sup&amp;gt;24&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt; +7888725a&amp;lt;sup&amp;gt;23&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt; +20160075a&amp;lt;sup&amp;gt;22&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; +44352165a&amp;lt;sup&amp;gt;21&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt; +84672315a&amp;lt;sup&amp;gt;20&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt; +141120525a&amp;lt;sup&amp;gt;19&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt; +206253075a&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt; +265182525a&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;14&amp;lt;/sup&amp;gt; +300540195a&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; +300540195a&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt; +265182525a&amp;lt;sup&amp;gt;14&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; +206253075a&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt; +141120525a&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;19&amp;lt;/sup&amp;gt; +84672315a&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;20&amp;lt;/sup&amp;gt; +44352165a&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;21&amp;lt;/sup&amp;gt; +20160075a&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;22&amp;lt;/sup&amp;gt; +7888725a&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;23&amp;lt;/sup&amp;gt; +2629575a&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;24&amp;lt;/sup&amp;gt; +736281a&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;25&amp;lt;/sup&amp;gt; +169911a&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;26&amp;lt;/sup&amp;gt; +31465a&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;27&amp;lt;/sup&amp;gt; +4495a&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;28&amp;lt;/sup&amp;gt; +465a&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt; +31ax&amp;lt;sup&amp;gt;30&amp;lt;/sup&amp;gt; +x&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     PolynomialRemainder [(x+a)&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;, x&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt;-1] =&lt;br /&gt;
       465a&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; +a&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt; +(31a+31a&amp;lt;sup&amp;gt;30&amp;lt;/sup&amp;gt;)x +(1+465a&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt;)x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; +4495a&amp;lt;sup&amp;gt;28&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; +31465a&amp;lt;sup&amp;gt;27&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; +169911a&amp;lt;sup&amp;gt;26&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt; +736281a&amp;lt;sup&amp;gt;25&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt; +2629575a&amp;lt;sup&amp;gt;24&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt; +7888725a&amp;lt;sup&amp;gt;23&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt; +20160075a&amp;lt;sup&amp;gt;22&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; +44352165a&amp;lt;sup&amp;gt;21&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt; +84672315a&amp;lt;sup&amp;gt;20&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt; +141120525a&amp;lt;sup&amp;gt;19&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt; +206253075a&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt; +265182525a&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;14&amp;lt;/sup&amp;gt; +300540195a&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt; +300540195a&amp;lt;sup&amp;gt;15&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;16&amp;lt;/sup&amp;gt; +265182525a&amp;lt;sup&amp;gt;14&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; +206253075a&amp;lt;sup&amp;gt;13&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt; +141120525a&amp;lt;sup&amp;gt;12&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;19&amp;lt;/sup&amp;gt; +84672315a&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;20&amp;lt;/sup&amp;gt; +44352165a&amp;lt;sup&amp;gt;10&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;21&amp;lt;/sup&amp;gt; +20160075a&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;22&amp;lt;/sup&amp;gt; +7888725a&amp;lt;sup&amp;gt;8&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;23&amp;lt;/sup&amp;gt; +2629575a&amp;lt;sup&amp;gt;7&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;24&amp;lt;/sup&amp;gt; +736281a&amp;lt;sup&amp;gt;6&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;25&amp;lt;/sup&amp;gt; +169911a&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;26&amp;lt;/sup&amp;gt; +31465a&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;27&amp;lt;/sup&amp;gt; +4495a&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;x&amp;lt;sup&amp;gt;28&amp;lt;/sup&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     ({{EquationRef|A}}) PolynomialMod [PolynomialRemainder [(x+a)&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;, x&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt;-1], 31] = a&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;+x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     ({{EquationRef|B}}) PolynomialRemainder [x&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;+a, x&amp;lt;sup&amp;gt;29&amp;lt;/sup&amp;gt;-1] = a+x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     ({{EquationNote|A}}) - ({{EquationNote|B}}) = a&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;+x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; - (a+x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;) = a&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;-a&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;math&amp;gt;\max = \left\lfloor\log_2 (31) \sqrt{\varphi(29)} \right\rfloor = 26&amp;lt;/math&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
     {1&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;-1 = 0 (mod 31), 2&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;-2 = 0 (mod 31), 3&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;-3 = 0 (mod 31), ..., 26&amp;lt;sup&amp;gt;31&amp;lt;/sup&amp;gt;-26 = 0 (mod 31)}&lt;br /&gt;
   &lt;br /&gt;
   &amp;lt;u&amp;gt;(* Step 6 *)&amp;lt;/u&amp;gt;&lt;br /&gt;
   &amp;#039;&amp;#039;&amp;#039;Output&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;prime&amp;#039;&amp;#039;.&lt;br /&gt;
     {{samp|31 Must be Prime}}&lt;br /&gt;
}}&lt;br /&gt;
Where PolynomialMod is a term-wise modulo reduction of the polynomial. e.g. PolynomialMod[x+2x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;+3x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;, 3] = x+2x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;+0x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;See [[Talk:AKS primality test#Worked Example|AKS Talk]] page for a discussion on why &amp;#039;Example 2: n is not Prime past Step 4&amp;#039; is missing.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==Further reading==&lt;br /&gt;
* {{cite book | last=Dietzfelbinger | first=Martin | title=Primality testing in polynomial time. From randomized algorithms to &amp;#039;&amp;#039;PRIMES is in P&amp;#039;&amp;#039; | series=Lecture Notes in Computer Science | volume=3000 | location=Berlin | publisher=[[Springer-Verlag]] | year=2004 | isbn=3-540-40344-2 | zbl=1058.11070 }}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* {{MathWorld|urlname=AKSPrimalityTest|title=AKS Primality Test}}&lt;br /&gt;
* [https://web.archive.org/web/20140219064936/http://www.dm.unito.it/~cerruti/ac/aks-crandall.pdf R. Crandall, Apple ACG, and J. Papadopoulos (March 18, 2003): On the implementation of AKS-class primality tests] (PDF)&lt;br /&gt;
* [https://www.ams.org/notices/200305/fea-bornemann.pdf Article by Bornemann, containing photos and information about the three Indian scientists] (PDF)&lt;br /&gt;
* [https://www.ams.org/bull/2005-42-01/S0273-0979-04-01037-7/home.html Andrew Granville: It is easy to determine whether a given integer is prime]&lt;br /&gt;
* [http://www.scottaaronson.com/writings/prime.pdf The Prime Facts: From Euclid to AKS], by [[Scott Aaronson]] (PDF)&lt;br /&gt;
* [http://www.instantlogic.net/publications/PRIMES%20is%20in%20P%20little%20FAQ.htm The PRIMES is in P little FAQ] by Anton Stiglic&lt;br /&gt;
* [https://web.archive.org/web/20150327071905/http://www.sigact.org/Prizes/Godel/2006.html 2006 Gödel Prize Citation]&lt;br /&gt;
* [https://www.ams.org/notices/200611/comm-fulkerson.pdf 2006 Fulkerson Prize Citation]&lt;br /&gt;
* [http://fatphil.org/maths/AKS The AKS &amp;quot;PRIMES in P&amp;quot; Algorithm Resource]&lt;br /&gt;
&lt;br /&gt;
{{Number theoretic algorithms}}&lt;br /&gt;
{{Authority control}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Indian inventions]]&lt;br /&gt;
[[Category:Primality tests]]&lt;br /&gt;
[[Category:Finite fields]]&lt;br /&gt;
[[Category:Articles with example pseudocode]]&lt;/div&gt;</summary>
		<author><name>Mythu09</name></author>
	</entry>
</feed>