<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Fermat_primality_test</id>
	<title>Fermat primality test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Fermat_primality_test"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Fermat_primality_test&amp;action=history"/>
	<updated>2026-06-16T02:11:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Fermat_primality_test&amp;diff=114714&amp;oldid=prev</id>
		<title>imported&gt;Artoria2e5: /* Corollaries */ ~</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Fermat_primality_test&amp;diff=114714&amp;oldid=prev"/>
		<updated>2025-11-06T09:25:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Corollaries: &lt;/span&gt; ~&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Probabilistic primality test}}&lt;br /&gt;
{{for|the test for determining whether a Fermat number is prime|Pépin&amp;#039;s test}}&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Fermat primality test&amp;#039;&amp;#039;&amp;#039; is a [[randomized algorithm|probabilistic]] test to determine whether a number is a [[probable prime]].&lt;br /&gt;
&lt;br /&gt;
==Concept==&lt;br /&gt;
[[Fermat&amp;#039;s little theorem]] states that if &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is prime and &amp;#039;&amp;#039;a&amp;#039;&amp;#039; is not divisible by &amp;#039;&amp;#039;p&amp;#039;&amp;#039;, then&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;a^{p-1} \equiv 1 \pmod{p}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If one wants to test whether &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is prime, then we can pick random integers &amp;#039;&amp;#039;a&amp;#039;&amp;#039; not divisible by &amp;#039;&amp;#039;p&amp;#039;&amp;#039; and see whether the congruence holds. If it does not hold for a value of &amp;#039;&amp;#039;a&amp;#039;&amp;#039;, then &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is composite. This congruence is unlikely to hold for a random &amp;#039;&amp;#039;a&amp;#039;&amp;#039; if &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is composite.&amp;lt;ref name=&amp;quot;PSW&amp;quot;&amp;gt;{{cite journal |author1 = Carl Pomerance |author-link1 = Carl Pomerance |author2 = John L. Selfridge |author-link2 = John L. Selfridge |author3 = Samuel S. Wagstaff, Jr. |author-link3 = Samuel S. Wagstaff, Jr. |title=The pseudoprimes to 25·10&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; |journal=Mathematics of Computation |date=July 1980 |volume=35 |issue=151 |pages=1003–1026 |url=//math.dartmouth.edu/~carlp/PDF/paper25.pdf |jstor=2006210 |doi=10.1090/S0025-5718-1980-0572872-7 |doi-access=free }}&amp;lt;/ref&amp;gt; Therefore, if the equality does hold for one or more values of &amp;#039;&amp;#039;a&amp;#039;&amp;#039;, then we say that &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is [[probable prime|probably prime]].&lt;br /&gt;
&lt;br /&gt;
However, note that the above congruence holds trivially for &amp;lt;math&amp;gt;a \equiv 1 \pmod{p}&amp;lt;/math&amp;gt;, because the congruence relation is [[Modular arithmetic#Basic properties|compatible with exponentiation]]. It also holds trivially for &amp;lt;math&amp;gt;a \equiv -1 \pmod{p}&amp;lt;/math&amp;gt; if &amp;#039;&amp;#039;p&amp;#039;&amp;#039; is odd, for the same reason. That is why one usually chooses a random &amp;#039;&amp;#039;a&amp;#039;&amp;#039; in the interval &amp;lt;math&amp;gt;1 &amp;lt; a &amp;lt; p - 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Any &amp;#039;&amp;#039;a&amp;#039;&amp;#039; such that &lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} \equiv 1 \pmod{n}&amp;lt;/math&amp;gt;&lt;br /&gt;
when &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is composite is known as a &amp;#039;&amp;#039;Fermat liar&amp;#039;&amp;#039;. In this case &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is called [[Fermat pseudoprime]] to base &amp;#039;&amp;#039;a&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
If we do pick an &amp;#039;&amp;#039;a&amp;#039;&amp;#039; such that &lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} \not\equiv 1 \pmod{n}&amp;lt;/math&amp;gt;&lt;br /&gt;
then &amp;#039;&amp;#039;a&amp;#039;&amp;#039; is known as a &amp;#039;&amp;#039;Fermat witness&amp;#039;&amp;#039; for the compositeness of &amp;#039;&amp;#039;n&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Suppose we wish to determine whether &amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;221 is prime. Randomly pick 1 &amp;lt; &amp;#039;&amp;#039;a&amp;#039;&amp;#039; &amp;lt; 220, say &amp;#039;&amp;#039;a&amp;#039;&amp;#039;&amp;amp;nbsp;=&amp;amp;nbsp;38. We check the above congruence and find that it holds:&lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} = 38^{220} \equiv 1 \pmod{221}.&amp;lt;/math&amp;gt;&lt;br /&gt;
Either 221 is prime, or 38 is a Fermat liar, so we take another &amp;#039;&amp;#039;a&amp;#039;&amp;#039;, say 24:&lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} = 24^{220} \equiv 81 \not\equiv 1 \pmod{221}.&amp;lt;/math&amp;gt;&lt;br /&gt;
So 221 is composite and 38 was indeed a Fermat liar. Furthermore, 24 is a Fermat witness for the compositeness of 221.&lt;br /&gt;
&lt;br /&gt;
==Algorithm==&lt;br /&gt;
The algorithm can be written as follows:&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;Inputs&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;n&amp;#039;&amp;#039;: a value to test for primality, &amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;gt;3; &amp;#039;&amp;#039;k&amp;#039;&amp;#039;: a parameter that determines the number of times to test for primality&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; if &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is composite, otherwise &amp;#039;&amp;#039;probably prime&amp;#039;&amp;#039;&lt;br /&gt;
:Repeat &amp;#039;&amp;#039;k&amp;#039;&amp;#039; times:&lt;br /&gt;
::Pick &amp;#039;&amp;#039;a&amp;#039;&amp;#039; randomly in the range [2, &amp;#039;&amp;#039;n&amp;#039;&amp;#039; &amp;amp;minus; 2]&lt;br /&gt;
::If &amp;lt;math&amp;gt;a^{n-1}\not\equiv1 \pmod n&amp;lt;/math&amp;gt;, then return &amp;#039;&amp;#039;composite&amp;#039;&amp;#039;&lt;br /&gt;
:If composite is never returned: return &amp;#039;&amp;#039;probably prime&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;a&amp;#039;&amp;#039; values 1 and &amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;amp;nbsp;−&amp;amp;nbsp;1 are not used as the equality holds for all &amp;#039;&amp;#039;n&amp;#039;&amp;#039; and all odd &amp;#039;&amp;#039;n&amp;#039;&amp;#039; respectively, hence testing them adds no value.&lt;br /&gt;
&lt;br /&gt;
=== Complexity ===&lt;br /&gt;
&lt;br /&gt;
Using fast algorithms for [[modular exponentiation]] and multiprecision multiplication, the running time of this algorithm is {{math|[[Big O notation|O]](&amp;#039;&amp;#039;k&amp;#039;&amp;#039; log&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039; log log &amp;#039;&amp;#039;n&amp;#039;&amp;#039;) {{=}} [[Big O notation#Extensions to the Bachmann–Landau notations|Õ]](&amp;#039;&amp;#039;k&amp;#039;&amp;#039;&amp;amp;nbsp;log&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;)}}, where &amp;#039;&amp;#039;k&amp;#039;&amp;#039; is the number of times we test a random &amp;#039;&amp;#039;a&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is the value we want to test for primality; see [[Miller–Rabin primality test#Complexity|Miller–Rabin primality test]] for details.&lt;br /&gt;
&lt;br /&gt;
==Flaw==&lt;br /&gt;
There are infinitely many [[Fermat pseudoprime]]s to any given basis &amp;#039;&amp;#039;a&amp;#039;&amp;#039; &amp;gt; 1.{{r|PSW|p=Theorem 1}}&lt;br /&gt;
Even worse, there are infinitely many [[Carmichael number]]s.&amp;lt;ref name=&amp;quot;Alford1994&amp;quot;&amp;gt;{{cite journal |last1=Alford |first1=W. R. |author-link=W. R. (Red) Alford |last2=Granville |first2=Andrew |author-link2=Andrew Granville |last3=Pomerance |first3=Carl |author-link3=Carl Pomerance |year=1994 |title=There are Infinitely Many Carmichael Numbers |journal=[[Annals of Mathematics]] |doi=10.2307/2118576 |volume=140 |issue=3 |pages=703–722 |url=http://www.math.dartmouth.edu/~carlp/PDF/paper95.pdf |jstor=2118576 }}&amp;lt;/ref&amp;gt; These are numbers &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; for which &amp;lt;em&amp;gt;all&amp;lt;/em&amp;gt; values of &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\operatorname{gcd}(a, n) = 1&amp;lt;/math&amp;gt; are Fermat liars. For these numbers, repeated application of the Fermat primality test performs the same as a simple random search for factors. While Carmichael numbers are substantially rarer than prime numbers (Erdős&amp;#039; upper bound for the number of Carmichael numbers&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite journal |author = Paul Erdős&lt;br /&gt;
 |date=1956 |title=On pseudoprimes and Carmichael numbers&lt;br /&gt;
 |journal=Publ. Math. Debrecen |volume=4 |pages=201–206|author-link=Paul Erdős|mr=0079031 }}&amp;lt;/ref&amp;gt; is lower than the [[Prime number theorem|prime number function n/log(n)]]) there are enough of them that Fermat&amp;#039;s primality test is not often used in the above form.  Instead, other more powerful extensions of the Fermat test, such as [[Baillie–PSW primality test|Baillie–PSW]], [[Miller–Rabin primality test|Miller–Rabin]], and [[Solovay–Strassen primality test|Solovay–Strassen]] are more commonly used.&lt;br /&gt;
&lt;br /&gt;
In general, if &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composite number that is not a Carmichael number, then at least half of all&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;a\in(\mathbb{Z}/n\mathbb{Z})^*&amp;lt;/math&amp;gt; (i.e. &amp;lt;math&amp;gt;\operatorname{gcd}(a,n)=1&amp;lt;/math&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
are Fermat witnesses.  For proof of this, let &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; be a Fermat witness and &amp;lt;math&amp;gt;a_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;a_2&amp;lt;/math&amp;gt;, ..., &amp;lt;math&amp;gt;a_s&amp;lt;/math&amp;gt; be Fermat liars.  Then&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;(a\cdot a_i)^{n-1} \equiv a^{n-1}\cdot a_i^{n-1} \equiv a^{n-1} \not\equiv 1\pmod{n}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and so all &amp;lt;math&amp;gt;a \cdot a_i&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;i = 1, 2, ..., s&amp;lt;/math&amp;gt; are Fermat witnesses.&lt;br /&gt;
&lt;br /&gt;
== Corollaries ==&lt;br /&gt;
Analogous to the [[Lucas–Lehmer residue]], &amp;lt;math&amp;gt;r = a^{n-1} \pmod{n}&amp;lt;/math&amp;gt; is called the &amp;#039;&amp;#039;&amp;#039;Fermet residue&amp;#039;&amp;#039;&amp;#039; of &amp;#039;&amp;#039;n&amp;#039;&amp;#039; to base &amp;#039;&amp;#039;a&amp;#039;&amp;#039;. There are a few variants that produce different types of residues,&amp;lt;ref name=&amp;quot;primenet&amp;quot;/&amp;gt; most importantly the [[strong probable prime]] (SPRP) residue.&amp;lt;ref&amp;gt;{{cite web |title=The Prime Glossary: strong probable prime |url=https://t5k.org/glossary/page.php?sort=StrongPRP |website=t5k.org}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Efficient exponentiation ===&lt;br /&gt;
For Mersenne numbers (or more broadly, any &amp;lt;math&amp;gt;n = 2^p - 1&amp;lt;/math&amp;gt;, &amp;#039;&amp;#039;p&amp;#039;&amp;#039; not necessarily a prime), it is more efficient to calculate &amp;lt;math&amp;gt;a^2r = a^{2^p} \pmod{n}&amp;lt;/math&amp;gt; than to calculate &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; due to [[exponentiation by squaring]] preferring a low [[Hamming weight]] (number of ones) in the exponent. The desired &amp;#039;&amp;#039;r&amp;#039;&amp;#039; may be recovered by multiplying by the [[modular inverse]] of &amp;lt;math&amp;gt;a^2&amp;lt;/math&amp;gt; mod &amp;#039;&amp;#039;n&amp;#039;&amp;#039;. It can alternatively be recovered by finding a small multiplier &amp;#039;&amp;#039;u&amp;#039;&amp;#039; such that &amp;lt;math&amp;gt;\operatorname{lift}(a^2r) + un&amp;lt;/math&amp;gt; is divisible by &amp;lt;math&amp;gt;a^2&amp;lt;/math&amp;gt; in ordinary integer arithmetic, then &amp;lt;math&amp;gt;r = (\operatorname{lift}(a^2r) + un) / a^2&amp;lt;/math&amp;gt;. This can proceed by trial and error, or by noticing that &amp;lt;math&amp;gt;u = \operatorname{modinv}(n, a^2)&amp;lt;/math&amp;gt;.&amp;lt;ref&amp;gt;{{cite web |last1=Mayer |first1=Ernst |title=Mlucas.c |url=https://github.com/primesearch/Mlucas/blob/6144ed0dcccd3a68f48c6ba92718c0bb78a4ba5c/src/Mlucas.c#L639}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing cofactors of &amp;#039;&amp;#039;n&amp;#039;&amp;#039; ===&lt;br /&gt;
If the residue &amp;#039;&amp;#039;r&amp;#039;&amp;#039; for &amp;#039;&amp;#039;n&amp;#039;&amp;#039; to base &amp;#039;&amp;#039;a&amp;#039;&amp;#039; is known, then for any proper divisor &amp;#039;&amp;#039;k&amp;#039;&amp;#039; of &amp;#039;&amp;#039;n&amp;#039;&amp;#039;, it is possible to perform a quick though weaker primality test on &amp;#039;&amp;#039;n&amp;#039;&amp;#039;/&amp;#039;&amp;#039;k&amp;#039;&amp;#039;. If &amp;#039;&amp;#039;n&amp;#039;&amp;#039;/&amp;#039;&amp;#039;k&amp;#039;&amp;#039; is prime, by Fermat&amp;#039;s theorem &amp;lt;math display=inline&amp;gt;a^{n/k} = a^k \pmod{n/k}&amp;lt;/math&amp;gt; and &amp;lt;math display=inline&amp;gt;a^n = a^k \pmod{n/k}&amp;lt;/math&amp;gt;. As a result &amp;lt;math display=inline&amp;gt;r = a^{k-1} \pmod{n/k}&amp;lt;/math&amp;gt;, which can be much more efficiently checked for values of &amp;#039;&amp;#039;k&amp;#039;&amp;#039; much smaller than &amp;#039;&amp;#039;n&amp;#039;&amp;#039;. (This is the method used by the [[Great Internet Mersenne Prime Search]] for testing cofactors.)&amp;lt;ref name=&amp;quot;primenet&amp;quot;&amp;gt;{{cite web |title=primenet.h |url=https://github.com/shafferjohn/Prime95/blob/6904c8d179103e77267219760b9ba7ea72325704/primenet.h#L262 |quote=There are (at least) 5 PRP residue types for testing N=(k*b^n+c)/d: (1) Fermat PRP.  Calculate a^(N-1) mod N.  PRP if result = 1. (2) SPRP variant.  Calculate a^((N-1)/2) mod N.  PRP if result = +/-1. (3) Type 1 variant,b=2,d=1. Calculate a^(N-c) mod N.  PRP if result = a^-(c-1). (4) Type 2 variant,b=2,d=1. Calculate a^((N-c)/2) mod N.  PRP if result = +/-a^-((c-1)/2). (5) Cofactor variant.  Calculate a^(N*d-1) mod N*d.  PRP if result = a^(d-1) mod N. }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A even weaker form of the test can be conducted with a truncated &amp;lt;math&amp;gt;a^n \pmod{n} \pmod{2^t}&amp;lt;/math&amp;gt; if storage space for the residue is a concern, so long as &amp;lt;math display=inline&amp;gt;d \leq 2^t&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n &amp;gt; 2^t&amp;lt;/math&amp;gt;. Let &amp;lt;math display=inline&amp;gt;s = a^k \pmod{n/k}&amp;lt;/math&amp;gt;, then &amp;lt;math display=inline&amp;gt;r = s+wn/k&amp;lt;/math&amp;gt; for some &amp;#039;&amp;#039;w&amp;#039;&amp;#039;. Take this mod 2&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;t&amp;#039;&amp;#039;&amp;lt;/sup&amp;gt; and we have &amp;lt;math display=inline&amp;gt;w = (n/k)^{-1}(s-r) \pmod{2^t}&amp;lt;/math&amp;gt;. &amp;#039;&amp;#039;n&amp;#039;&amp;#039;/&amp;#039;&amp;#039;k&amp;#039;&amp;#039; is composite if &amp;lt;math&amp;gt;w \geq d&amp;lt;/math&amp;gt;. A similar test can be done on truncated Lucas–Lehmer residues.&amp;lt;ref&amp;gt;{{cite web |last1=Gerbicz |first1=Robert |title=Saving tons of PRP-C and (hypotetical) LL-C tests, a new method |url=https://www.mersenneforum.org/node/17770?t=23462 |website=www.mersenneforum.org |language=en |date=2018-06-22|url-access=registration}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Path to being deterministic ===&lt;br /&gt;
It is also true that if all bases &amp;#039;&amp;#039;a&amp;#039;&amp;#039; are systematically checked in the interval &amp;lt;math&amp;gt;[2,\sqrt{n}]&amp;lt;/math&amp;gt;, each demonstrating congruence to 1, the test is effectively deterministic. We may say that &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is definitely prime. At cursory glance one may assume that &amp;#039;&amp;#039;n&amp;#039;&amp;#039; exists in the union of both primes and Carmichael numbers for such a scenario, but if &amp;#039;&amp;#039;a&amp;#039;&amp;#039;-values are systematically checked in the interval, one is bound to be a prime factor of a composite &amp;#039;&amp;#039;n&amp;#039;&amp;#039; at some point before &amp;lt;math&amp;gt;\sqrt{n}&amp;lt;/math&amp;gt;, thus making &amp;#039;&amp;#039;a&amp;#039;&amp;#039; and &amp;#039;&amp;#039;n&amp;#039;&amp;#039; not coprime, and failing the congruence, even if &amp;#039;&amp;#039;n&amp;#039;&amp;#039; is indeed a Carmichael number. Carmichael numbers do fail Fermat&amp;#039;s congruence to 1 if the base used is not coprime. Though this is more computationally expensive than brute force divisibility checking (trial division), it is of theoretical value.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
As mentioned above, most applications use a [[Miller–Rabin primality test|Miller–Rabin]] or [[Baillie–PSW primality test|Baillie–PSW]] test for primality.  Sometimes a Fermat test (along with some trial division by small primes) is performed first to improve performance.  [[GNU Multiple Precision Arithmetic Library|GMP]] since version 3.0 uses a base-210 Fermat test after trial division and before running Miller–Rabin tests.  [[Libgcrypt]] uses a similar process with base 2 for the Fermat test, but [[OpenSSL]] does not.&lt;br /&gt;
&lt;br /&gt;
In practice with most big number libraries such as GMP, the Fermat test is not noticeably faster than a Miller–Rabin test, and can be slower for many inputs.&amp;lt;ref&amp;gt;{{citation|author=Joe Hurd|date=2003|title=Verification of the Miller–Rabin Probabilistic Primality Test|page=2|citeseerx=10.1.1.105.3196}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As an exception, OpenPFGW uses only the Fermat test for probable prime testing.  The program is typically used with multi-thousand digit inputs with a goal of maximum speed with very large inputs.  Another well known program that relies only on the Fermat test is [[Pretty Good Privacy|PGP]] where it is only used for testing of self-generated large random values (an open source counterpart, [[GNU Privacy Guard]], uses a Fermat pretest followed by Miller–Rabin tests).&lt;br /&gt;
&lt;br /&gt;
=== Prime number search projects ===&lt;br /&gt;
Internet [[volunteer computing]] projects such as [[Great Internet Mersenne Prime Search]] (GIMPS) and [[PrimeGrid]] use the Fermat primality test because there is an efficient proof scheme (Gerbicz-Li) for modular exponentiation. Selected intermediate results, combined with a [[verifiable delay function]], are used to generate a &amp;quot;[[Primality certificate|proof]]&amp;quot; file for verifying the authenticity and correctness of the computation, protecting against both hardware error and malicious actors. This proof is hard to forge given a low order assumption. The original form of the verification (Gerbicz-Pietrzak) only worked with &amp;#039;&amp;#039;n&amp;#039;&amp;#039; being derivable from powers of 2, such as in the case of Mersenne primes, Mersenne cofactors, and Proth primes; Li&amp;#039;s modification generalizes it to any &amp;#039;&amp;#039;n&amp;#039;&amp;#039;.&amp;lt;ref&amp;gt;{{cite web |author1=Darren Li|author2=Yves Gallot|title=An Efficient Modular Exponentiation Proof Scheme |url=https://arxiv.org/abs/2209.15623 |website=arXiv |date=8 Feb 2023}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The GIMPS in particular tests Mersenne primes and Mersenne cofactors. The default is to use &amp;#039;&amp;#039;a&amp;#039;&amp;#039; = 3 as all Mersenne numbers would pass the test with &amp;#039;&amp;#039;a&amp;#039;&amp;#039; = 2.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
* {{cite book |author1=[[Thomas H. Cormen]]|author2=[[Charles E. Leiserson]]|author3= [[Ronald L. Rivest]]|author4= [[Clifford Stein]] |title=Introduction to Algorithms |edition=Second |publisher=MIT Press; McGraw-Hill |year=2001 |isbn=0-262-03293-7 |page=889&amp;amp;ndash;890 |chapter=Section 31.8: Primality testing|title-link=Introduction to Algorithms }}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Pierre de Fermat}}&lt;br /&gt;
{{number theoretic algorithms}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Primality tests]]&lt;br /&gt;
[[Category:Modular arithmetic]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Artoria2e5</name></author>
	</entry>
</feed>