<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2602%3A306%3ACE33%3AB4A0%3AD92E%3AE6D3%3AEFD5%3AE27D</id>
	<title>TCS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2602%3A306%3ACE33%3AB4A0%3AD92E%3AE6D3%3AEFD5%3AE27D"/>
	<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Special:Contributions/2602:306:CE33:B4A0:D92E:E6D3:EFD5:E27D"/>
	<updated>2026-05-26T16:12:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Fermat%27s_primality_test&amp;diff=7510</id>
		<title>Fermat&#039;s primality test</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Fermat%27s_primality_test&amp;diff=7510"/>
		<updated>2016-06-09T22:05:00Z</updated>

		<summary type="html">&lt;p&gt;2602:306:CE33:B4A0:D92E:E6D3:EFD5:E27D: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Fermat&#039;s primality test&#039;&#039;&#039; is an [[algorithm]]. It can test if a given number &#039;&#039;p&#039;&#039; is probably [[prime number|prime]]. There is a [[flaw]] however: There are numbers that pass the test, and that are not prime. These numbers are called [[Carmichael number]]s.&lt;br /&gt;
&lt;br /&gt;
==Concept== &lt;br /&gt;
[[Fermat&#039;s little theorem]] states that if &#039;&#039;p&#039;&#039; is prime and &amp;lt;math&amp;gt;1 \le a &amp;lt; p&amp;lt;/math&amp;gt;, 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 we want to test if &#039;&#039;n&#039;&#039; is prime, then we can pick random &#039;&#039;a&#039;&#039;&#039;s in the [[interval]] and see if the [[equation]] above holds.  If the equality does not hold for a value of &#039;&#039;a&#039;&#039;, then &#039;&#039;n&#039;&#039; is [[composite number|composite]] (not prime).  If the equality does hold for many values of &#039;&#039;a&#039;&#039;, then we can say that &#039;&#039;n&#039;&#039; is probably prime, or a [[pseudoprime]].&lt;br /&gt;
&lt;br /&gt;
It may be in our tests that we do not pick any value for &#039;&#039;a&#039;&#039; such that the equality fails.  Any &#039;&#039;a&#039;&#039; such that &lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} \equiv 1 \pmod{n}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
when &#039;&#039;n&#039;&#039; is composite is known as a &#039;&#039;Fermat liar&#039;&#039;.  If we do pick an &#039;&#039;a&#039;&#039; such that &lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;a^{n-1} \not\equiv 1 \pmod{n}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
then &#039;&#039;a&#039;&#039; is known as a &#039;&#039;Fermat witness&#039;&#039; for the compositeness of &#039;&#039;n&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;math&amp;gt;\pmod n&amp;lt;/math&amp;gt;&#039;&#039; is the [[Modular arithmetic|modulo]] operation. Its result is what remains, if p is divided by n. As an example,&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt; 5 \equiv 2 \pmod 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==What this test is used for==&lt;br /&gt;
The [[RSA algorithm]] for [[Public-key cryptography|public-key encryption]] can be done in such a way that it uses this test. This is useful in [[cryptography]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Computer science]]&lt;br /&gt;
[[Category:Number theory]]&lt;/div&gt;</summary>
		<author><name>2602:306:CE33:B4A0:D92E:E6D3:EFD5:E27D</name></author>
	</entry>
</feed>