<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://conwaylife.com/w/index.php?action=history&amp;feed=atom&amp;title=Modular_congruence</id>
	<title>Modular congruence - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://conwaylife.com/w/index.php?action=history&amp;feed=atom&amp;title=Modular_congruence"/>
	<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;action=history"/>
	<updated>2026-12-06T06:10:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=146616&amp;oldid=prev</id>
		<title>DroneBetter: fix leading sentence&#039;s grammar (copied mistakenly), note coprimeness requirement for Euler&#039;s theorem and alternative version of Fermat&#039;s little theorem</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=146616&amp;oldid=prev"/>
		<updated>2024-03-07T15:30:47Z</updated>

		<summary type="html">&lt;p&gt;fix leading sentence&amp;#039;s grammar (copied mistakenly), note coprimeness requirement for Euler&amp;#039;s theorem and alternative version of Fermat&amp;#039;s little theorem&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:30, 7 March 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{cleanup}}{{Glossary}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{cleanup}}{{Glossary}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let &amp;lt;tt&amp;gt;p%q = p-⌊{{frac|p|q}}⌋*q&amp;lt;/tt&amp;gt; (&quot;&amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; modulo &amp;lt;tt&amp;gt;q&amp;lt;/tt&amp;gt;&quot;), ie. adding or subtracting integer multiples of &amp;lt;tt&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;p&lt;/del&gt;&amp;lt;/tt&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;are added or subtracted from &lt;/del&gt;&amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; such that it lies in the range &amp;lt;tt&amp;gt;0 &amp;amp;le; x &amp;lt; q&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&quot;n&quot;&amp;gt;Note that for &amp;lt;tt&amp;gt;p &amp;amp;ne; 0&amp;lt;/tt&amp;gt;, this causes &amp;lt;tt&amp;gt;sgn(p%q) = sgn(q)&amp;lt;/tt&amp;gt;, to make &amp;lt;tt&amp;gt;⌊{{frac|p|q}}⌋*q+p%q=p&amp;lt;/tt&amp;gt; hold, as in Python. In other programming languages such as C, &amp;lt;tt&amp;gt;p%q = |p-⌊{{frac|p|q}}⌋*q|*sgn(p)&amp;lt;/tt&amp;gt;, so ie. &amp;lt;tt&amp;gt;-4%3=-1&amp;lt;/tt&amp;gt;, since its integer integer division operator, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, rounds towards &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt; instead of &amp;lt;tt&amp;gt;-∞&amp;lt;/tt&amp;gt;. In most programming languages, modulo has the same precedence as multiplication and division, and expressions involving multiple of the same precedence adjacent without brackets are evaluated left-to-right.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let &amp;lt;tt&amp;gt;p%q = p-⌊{{frac|p|q}}⌋*q&amp;lt;/tt&amp;gt; (&quot;&amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; modulo &amp;lt;tt&amp;gt;q&amp;lt;/tt&amp;gt;&quot;), ie. adding or subtracting integer multiples of &amp;lt;tt&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;q&lt;/ins&gt;&amp;lt;/tt&amp;gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to &lt;/ins&gt;&amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; such that it lies in the range &amp;lt;tt&amp;gt;0 &amp;amp;le; x &amp;lt; q&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&quot;n&quot;&amp;gt;Note that for &amp;lt;tt&amp;gt;p &amp;amp;ne; 0&amp;lt;/tt&amp;gt;, this causes &amp;lt;tt&amp;gt;sgn(p%q) = sgn(q)&amp;lt;/tt&amp;gt;, to make &amp;lt;tt&amp;gt;⌊{{frac|p|q}}⌋*q+p%q=p&amp;lt;/tt&amp;gt; hold, as in Python. In other programming languages such as C, &amp;lt;tt&amp;gt;p%q = |p-⌊{{frac|p|q}}⌋*q|*sgn(p)&amp;lt;/tt&amp;gt;, so ie. &amp;lt;tt&amp;gt;-4%3=-1&amp;lt;/tt&amp;gt;, since its integer integer division operator, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, rounds towards &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt; instead of &amp;lt;tt&amp;gt;-∞&amp;lt;/tt&amp;gt;. In most programming languages, modulo has the same precedence as multiplication and division, and expressions involving multiple of the same precedence adjacent without brackets are evaluated left-to-right.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Two numbers &amp;lt;tt&amp;gt;a,b&amp;lt;/tt&amp;gt; are &amp;#039;&amp;#039;&amp;#039;congruent&amp;#039;&amp;#039;&amp;#039; modulo a third number &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; {{iff}} &amp;lt;tt&amp;gt;a%n = b%n&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Two numbers &amp;lt;tt&amp;gt;a,b&amp;lt;/tt&amp;gt; are &amp;#039;&amp;#039;&amp;#039;congruent&amp;#039;&amp;#039;&amp;#039; modulo a third number &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; {{iff}} &amp;lt;tt&amp;gt;a%n = b%n&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l31&quot;&gt;Line 31:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 31:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These provide algebraic reduction steps for forms that can arise generally in modular arithmetic problems.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These provide algebraic reduction steps for forms that can arise generally in modular arithmetic problems.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Fermat&amp;#039;s_little_theorem|name=Fermat&amp;#039;s little theorem|nobullet=no|nosuffix=no}} states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt; ≡ c (mod p)&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Being prime is sufficient but not necessary, composite &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; for which &amp;lt;tt&amp;gt;n&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt; ≡ n (mod p)&amp;lt;/tt&amp;gt; are called Fermat pseudoprimes to base &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;. The smallest composite pseudoprime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;{{OEIS|A000790|tt=tt}}(n)&amp;lt;/tt&amp;gt;, which is periodic over &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; with period &amp;lt;tt&amp;gt;277# * 23#&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt; is the primorial.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Fermat&amp;#039;s_little_theorem|name=Fermat&amp;#039;s little theorem|nobullet=no|nosuffix=no}} states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt; ≡ c (mod p)&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Being prime is sufficient but not necessary, composite &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; for which &amp;lt;tt&amp;gt;n&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt; ≡ n (mod p)&amp;lt;/tt&amp;gt; are called Fermat pseudoprimes to base &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;. The smallest composite pseudoprime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;{{OEIS|A000790|tt=tt}}(n)&amp;lt;/tt&amp;gt;, which is periodic over &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; with period &amp;lt;tt&amp;gt;277# * 23#&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt; is the primorial.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:: It is also given as &amp;lt;tt&amp;gt;c&amp;lt;sup&amp;gt;p-1&amp;lt;/sup&amp;gt; ≡ 1 (mod p)&amp;lt;/tt&amp;gt;, however this pertains only for coprime &amp;lt;tt&amp;gt;c,p&amp;lt;/tt&amp;gt;, whereas &amp;lt;tt&amp;gt;c&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt; ≡ n (mod p)&amp;lt;/tt&amp;gt; is irrespective&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Wilson&amp;#039;s_theorem|name=Wilson&amp;#039;s theorem|nobullet=no|nosuffix=no}} states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt; if &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is prime, otherwise &amp;lt;tt&amp;gt;(n-1)! ≡ 0 (mod n)&amp;lt;/tt&amp;gt; unless &amp;lt;tt&amp;gt;n = 4&amp;lt;/tt&amp;gt;, in which case it is congruent instead to &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Explained as an exercise in the MODA chapter involving placements of rooks on toroidal chessboards, and in [[Pólya_enumeration_theorem#Wilson&amp;#039;s_theorem|the Pólya enumeration theorem article]]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Wilson&amp;#039;s_theorem|name=Wilson&amp;#039;s theorem|nobullet=no|nosuffix=no}} states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt; if &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is prime, otherwise &amp;lt;tt&amp;gt;(n-1)! ≡ 0 (mod n)&amp;lt;/tt&amp;gt; unless &amp;lt;tt&amp;gt;n = 4&amp;lt;/tt&amp;gt;, in which case it is congruent instead to &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Explained as an exercise in the MODA chapter involving placements of rooks on toroidal chessboards, and in [[Pólya_enumeration_theorem#Wilson&amp;#039;s_theorem|the Pólya enumeration theorem article]]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Lucas&amp;#039;s_theorem|name=Lucas&amp;#039;s theorem|nobullet=no|nosuffix=no}}: &amp;lt;tt&amp;gt;{{choose|n|k}} ≡ {{product|i{{=}}0|∞|{{choose|n&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;|k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;}}|brac=}}&amp;lt;!--{{product|i{{=}}0|∞|{{choose|⌊{{frac|n|b&amp;lt;sup&amp;gt;i&amp;lt;/sup&amp;gt;}}⌋%b|⌊{{frac|k|b&amp;lt;sup&amp;gt;i&amp;lt;/sup&amp;gt;}}⌋%b}}|brac=}}--&amp;gt; (mod b)&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;n&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; is the &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;th base-&amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; digit of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Lucas&amp;#039;s_theorem|name=Lucas&amp;#039;s theorem|nobullet=no|nosuffix=no}}: &amp;lt;tt&amp;gt;{{choose|n|k}} ≡ {{product|i{{=}}0|∞|{{choose|n&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;|k&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;}}|brac=}}&amp;lt;!--{{product|i{{=}}0|∞|{{choose|⌊{{frac|n|b&amp;lt;sup&amp;gt;i&amp;lt;/sup&amp;gt;}}⌋%b|⌊{{frac|k|b&amp;lt;sup&amp;gt;i&amp;lt;/sup&amp;gt;}}⌋%b}}|brac=}}--&amp;gt; (mod b)&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;n&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;&amp;lt;/tt&amp;gt; is the &amp;lt;tt&amp;gt;i&amp;lt;/tt&amp;gt;th base-&amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; digit of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===for {{LinkWikipedia|Modular_exponentiation|name=modular exponentiation|nobullet=no|nosuffix=no}} computation===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===for {{LinkWikipedia|Modular_exponentiation|name=modular exponentiation|nobullet=no|nosuffix=no}} computation===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;tt&amp;gt;x*y ≡ (x%n)*(y%n) (mod n)&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt;%n&amp;lt;/tt&amp;gt; can be calculated as &amp;lt;tt&amp;gt;(( ... (((x%n)*x)%n)* ... )*x)%n&amp;lt;/tt&amp;gt; (preventing any number partway through the computation from exceeding &amp;lt;tt&amp;gt;(n-1)*x&amp;lt;/tt&amp;gt;)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;tt&amp;gt;x*y ≡ (x%n)*(y%n) (mod n)&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;p&amp;lt;/sup&amp;gt;%n&amp;lt;/tt&amp;gt; can be calculated as &amp;lt;tt&amp;gt;(( ... (((x%n)*x)%n)* ... )*x)%n&amp;lt;/tt&amp;gt; (preventing any number partway through the computation from exceeding &amp;lt;tt&amp;gt;(n-1)*x&amp;lt;/tt&amp;gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Euler&#039;s_theorem|name=Euler&#039;s theorem|nobullet=no|nosuffix=no}}: &amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;φ(m)&amp;lt;/sup&amp;gt; ≡ 1 (mod m)&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; ≡ x&amp;lt;sup&amp;gt;n%φ(m)&amp;lt;/sup&amp;gt; (mod m)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* {{LinkWikipedia|Euler&#039;s_theorem|name=Euler&#039;s theorem|nobullet=no|nosuffix=no}}: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;For coprime &amp;lt;tt&amp;gt;x,m&amp;lt;/tt&amp;gt; &lt;/ins&gt;&amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;φ(m)&amp;lt;/sup&amp;gt; ≡ 1 (mod m)&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;x&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; ≡ x&amp;lt;sup&amp;gt;n%φ(m)&amp;lt;/sup&amp;gt; (mod m)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:* If &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is computed from its factorisation, &amp;lt;tt&amp;gt;n%φ(m)&amp;lt;/tt&amp;gt; can be computed efficiently also&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:* If &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is computed from its factorisation, &amp;lt;tt&amp;gt;n%φ(m)&amp;lt;/tt&amp;gt; can be computed efficiently also&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:* Note that Fermat&amp;#039;s little theorem is the special case of Euler&amp;#039;s theorem, since for primes &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;φ(p) = p-1&amp;lt;/tt&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:* Note that Fermat&amp;#039;s little theorem is the special case of Euler&amp;#039;s theorem, since for primes &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;φ(p) = p-1&amp;lt;/tt&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>DroneBetter</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=146608&amp;oldid=prev</id>
		<title>DroneBetter: make slightly more nicely formatted and well-explained and less egregious in the way of footnotery</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=146608&amp;oldid=prev"/>
		<updated>2024-03-07T13:11:42Z</updated>

		<summary type="html">&lt;p&gt;make slightly more nicely formatted and well-explained and less egregious in the way of footnotery&lt;/p&gt;
&lt;a href=&quot;https://conwaylife.com/w/index.php?title=Modular_congruence&amp;amp;diff=146608&amp;amp;oldid=137874&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>DroneBetter</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=137874&amp;oldid=prev</id>
		<title>DroneBetter: clean up and reword somewhat (using {{frac}}, {{choose}} and {{prod}}, of which I learned since writing this page), add Lucas&#039;s and Euler&#039;s theorems</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=137874&amp;oldid=prev"/>
		<updated>2023-09-30T13:36:22Z</updated>

		<summary type="html">&lt;p&gt;clean up and reword somewhat (using {{frac}}, {{choose}} and {{prod}}, of which I learned since writing this page), add Lucas&amp;#039;s and Euler&amp;#039;s theorems&lt;/p&gt;
&lt;a href=&quot;https://conwaylife.com/w/index.php?title=Modular_congruence&amp;amp;diff=137874&amp;amp;oldid=131790&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>DroneBetter</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=131790&amp;oldid=prev</id>
		<title>DroneBetter: Now I should look quite the fool</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=131790&amp;oldid=prev"/>
		<updated>2023-05-31T00:54:13Z</updated>

		<summary type="html">&lt;p&gt;Now I should look quite the fool&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:54, 31 May 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These provide algebraic reduction steps for forms that can arise generally in modular arithmetic problems.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;These provide algebraic reduction steps for forms that can arise generally in modular arithmetic problems.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Fermat&amp;#039;s_little_theorem Fermat&amp;#039;s little theorem] states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c**p≡c (mod p)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Fermat&amp;#039;s_little_theorem Fermat&amp;#039;s little theorem] states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c**p≡c (mod p)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Wilson&#039;s_theorem Wilson&#039;s theorem] states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Wilson&#039;s_theorem Wilson&#039;s theorem] states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/tt&amp;gt; if &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is prime, otherwise &amp;lt;tt&amp;gt;(n-1)! ≡ 0 (mod n)&amp;lt;/tt&amp;gt; unless &amp;lt;tt&amp;gt;n=4&amp;lt;/tt&amp;gt;, in which case it is congruent instead to &amp;lt;tt&amp;gt;2&lt;/ins&gt;&amp;lt;/tt&amp;gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;ref group=&quot;n&quot;&amp;gt;Explained as an exercise in the MODA chapter involving placements of rooks on toroidal chessboards, and in [[Pólya_enumeration_theorem#Wilson&#039;s_theorem|the Pólya enumeration theorem article]]&amp;lt;/ref&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Uses in Conway&amp;#039;s Game of Life==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Uses in Conway&amp;#039;s Game of Life==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l30&quot;&gt;Line 30:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 30:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==See also==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==See also==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Pólya enumeration theorem]] (through &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;application of a corollary of &lt;/del&gt;which&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;the theorems above can be proven)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Pólya enumeration theorem]] (&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the enumeration equations must return integers, so the division in the averaging is equivalent to floordiv, meaning the output of the equivalent modulo must be &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;, &lt;/ins&gt;through which the theorems above can be proven)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Notes==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Notes==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>DroneBetter</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130566&amp;oldid=prev</id>
		<title>HotdogPi: section: &quot;Uses in Conway&#039;s Game of Life&quot;</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130566&amp;oldid=prev"/>
		<updated>2023-05-09T14:01:34Z</updated>

		<summary type="html">&lt;p&gt;section: &amp;quot;Uses in Conway&amp;#039;s Game of Life&amp;quot;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:01, 9 May 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l19&quot;&gt;Line 19:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 19:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Fermat&amp;#039;s_little_theorem Fermat&amp;#039;s little theorem] states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c**p≡c (mod p)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Fermat&amp;#039;s_little_theorem Fermat&amp;#039;s little theorem] states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c**p≡c (mod p)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Wilson&amp;#039;s_theorem Wilson&amp;#039;s theorem] states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://en.wikipedia.org/wiki/Wilson&amp;#039;s_theorem Wilson&amp;#039;s theorem] states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==Uses in Conway&#039;s Game of Life==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Colour]] is mod 2.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Trombone slide]]s are mod 8.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Filter]]s for glider streams require certain characteristics, e.g. 8 mod 16 for [[Rich&#039;s p16]] and 5 mod 15 or 10 mod 15 for [[Karel&#039;s p15]].&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Phase shift]]ers make use of modular arithmetic, e.g. [[28P7.1]] phase shifts once when the overall period is 1 mod 7.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Pentadecathlon]] phase shifters work when the overall period is 6, 9, or 14 mod 15, depending on the mechanism. 6 corresponds to the [[monoicosathlon]], 9 to one modification of the [[p54 shuttle]], and 14 to the [[p44 pi-heptomino hassler]].&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Many of the [[SKOP|smallest known oscillators of a period]] that are part of infinite families rely on modular arithmetic, such as [[6 bits]] being 45 mod 120 and the number of gliders required in a [[rectifier]] being dependent on period mod 8 and the existence of a working 22hd reflector requiring the period being 4 mod 8.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==See also==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==See also==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>HotdogPi</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130546&amp;oldid=prev</id>
		<title>Confocal: stub &amp;rarr; cleanup (inline external links related Talk:Hat#Links and markup, other formatting)</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130546&amp;oldid=prev"/>
		<updated>2023-05-09T02:16:50Z</updated>

		<summary type="html">&lt;p&gt;stub → cleanup (inline external links related &lt;a href=&quot;/wiki/Talk:Hat#Links_and_markup&quot; title=&quot;Talk:Hat&quot;&gt;Talk:Hat#Links and markup&lt;/a&gt;, other formatting)&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:16, 9 May 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;stub&lt;/del&gt;}}{{Glossary}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;cleanup&lt;/ins&gt;}}{{Glossary}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Two numbers &amp;lt;tt&amp;gt;a,b&amp;lt;/tt&amp;gt; are &amp;#039;&amp;#039;&amp;#039;congruent&amp;#039;&amp;#039;&amp;#039; modulo a third number &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; if their values are equal when integer multiples of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; are added or subtracted from them such that they both lie in the range &amp;lt;tt&amp;gt;0&amp;lt;=x&amp;lt;n&amp;lt;/tt&amp;gt; (an operation denoted with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; symbol).&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;When either operand is negative, programming languages&amp;#039; implementations differ in convention. Python ensures that the sign of the output matches that of the second input (the &amp;#039;modulo base&amp;#039;), ie. &amp;lt;tt&amp;gt;0&amp;gt;=x%n&amp;gt;n&amp;lt;/tt&amp;gt; if n is negative, to make &amp;lt;tt&amp;gt;x//n*n+x%n=x&amp;lt;/tt&amp;gt; hold, because Python&amp;#039;s floordiv operator &amp;lt;tt&amp;gt;//&amp;lt;/tt&amp;gt; rounds towards &amp;lt;tt&amp;gt;-∞&amp;lt;/tt&amp;gt;, whereas C matches the first, ie. &amp;lt;tt&amp;gt;-4%3=-1&amp;lt;/tt&amp;gt;, because its integer division operator, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, returns integers but rounds towards &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;, this article will use the Python convention for signed modulo.&amp;lt;/ref&amp;gt; A function returning the value of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; modulo &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is given in most programming languages with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; operator (ie. &amp;lt;tt&amp;gt;x%n&amp;lt;/tt&amp;gt;), and according to the C specification (followed by languages like Python), modulo has the same precedence as multiplication and division, and expressions involving multiple of the same precedence adjacent without brackets will be evaluated left-to-right.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Without modulo or floordiv (only multiplication and division), this is equivalent to division being evaluated before multiplication, as is taught in schools.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Two numbers &amp;lt;tt&amp;gt;a,b&amp;lt;/tt&amp;gt; are &amp;#039;&amp;#039;&amp;#039;congruent&amp;#039;&amp;#039;&amp;#039; modulo a third number &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; if their values are equal when integer multiples of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; are added or subtracted from them such that they both lie in the range &amp;lt;tt&amp;gt;0&amp;lt;=x&amp;lt;n&amp;lt;/tt&amp;gt; (an operation denoted with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; symbol).&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;When either operand is negative, programming languages&amp;#039; implementations differ in convention. Python ensures that the sign of the output matches that of the second input (the &amp;#039;modulo base&amp;#039;), ie. &amp;lt;tt&amp;gt;0&amp;gt;=x%n&amp;gt;n&amp;lt;/tt&amp;gt; if n is negative, to make &amp;lt;tt&amp;gt;x//n*n+x%n=x&amp;lt;/tt&amp;gt; hold, because Python&amp;#039;s floordiv operator &amp;lt;tt&amp;gt;//&amp;lt;/tt&amp;gt; rounds towards &amp;lt;tt&amp;gt;-∞&amp;lt;/tt&amp;gt;, whereas C matches the first, ie. &amp;lt;tt&amp;gt;-4%3=-1&amp;lt;/tt&amp;gt;, because its integer division operator, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, returns integers but rounds towards &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;, this article will use the Python convention for signed modulo.&amp;lt;/ref&amp;gt; A function returning the value of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; modulo &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is given in most programming languages with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; operator (ie. &amp;lt;tt&amp;gt;x%n&amp;lt;/tt&amp;gt;), and according to the C specification (followed by languages like Python), modulo has the same precedence as multiplication and division, and expressions involving multiple of the same precedence adjacent without brackets will be evaluated left-to-right.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Without modulo or floordiv (only multiplication and division), this is equivalent to division being evaluated before multiplication, as is taught in schools.&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Confocal</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130545&amp;oldid=prev</id>
		<title>Confocal: +</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130545&amp;oldid=prev"/>
		<updated>2023-05-09T02:08:03Z</updated>

		<summary type="html">&lt;p&gt;+&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:08, 9 May 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l26&quot;&gt;Line 26:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 26:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references group=&amp;quot;n&amp;quot;&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;references group=&amp;quot;n&amp;quot;&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;External links&lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Further reading &lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [[Conway&#039;s Game of Life: Mathematics and Construction]], Appendix A.1 Modular Congruence&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://cp4space.files.wordpress.com/2012/09/moda-ch01.pdf Combinatorics I], the first chapter of [[Adam P. Goucher]]&amp;#039;s book, &amp;#039;&amp;#039;Mathematical Olympiad Dark Arts&amp;#039;&amp;#039; (that explains a great deal more about modular arithmetic than this)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://cp4space.files.wordpress.com/2012/09/moda-ch01.pdf Combinatorics I], the first chapter of [[Adam P. Goucher]]&amp;#039;s book, &amp;#039;&amp;#039;Mathematical Olympiad Dark Arts&amp;#039;&amp;#039; (that explains a great deal more about modular arithmetic than this)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;__NOTOC__&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithms]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithms]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Mathematical miscellany]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Mathematical miscellany]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;__NOTOC__&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Confocal</name></author>
	</entry>
	<entry>
		<id>https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130543&amp;oldid=prev</id>
		<title>DroneBetter: Create (it is linked to (not by me) in 6 different pages so seemed to warrant it, though it is not very detailed (in the congruence part, at least) thus far)</title>
		<link rel="alternate" type="text/html" href="https://conwaylife.com/w/index.php?title=Modular_congruence&amp;diff=130543&amp;oldid=prev"/>
		<updated>2023-05-09T01:56:38Z</updated>

		<summary type="html">&lt;p&gt;Create (it is linked to (not by me) in 6 different pages so seemed to warrant it, though it is not very detailed (in the congruence part, at least) thus far)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{stub}}{{Glossary}}&lt;br /&gt;
Two numbers &amp;lt;tt&amp;gt;a,b&amp;lt;/tt&amp;gt; are &amp;#039;&amp;#039;&amp;#039;congruent&amp;#039;&amp;#039;&amp;#039; modulo a third number &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; if their values are equal when integer multiples of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; are added or subtracted from them such that they both lie in the range &amp;lt;tt&amp;gt;0&amp;lt;=x&amp;lt;n&amp;lt;/tt&amp;gt; (an operation denoted with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; symbol).&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;When either operand is negative, programming languages&amp;#039; implementations differ in convention. Python ensures that the sign of the output matches that of the second input (the &amp;#039;modulo base&amp;#039;), ie. &amp;lt;tt&amp;gt;0&amp;gt;=x%n&amp;gt;n&amp;lt;/tt&amp;gt; if n is negative, to make &amp;lt;tt&amp;gt;x//n*n+x%n=x&amp;lt;/tt&amp;gt; hold, because Python&amp;#039;s floordiv operator &amp;lt;tt&amp;gt;//&amp;lt;/tt&amp;gt; rounds towards &amp;lt;tt&amp;gt;-∞&amp;lt;/tt&amp;gt;, whereas C matches the first, ie. &amp;lt;tt&amp;gt;-4%3=-1&amp;lt;/tt&amp;gt;, because its integer division operator, &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;, returns integers but rounds towards &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;, this article will use the Python convention for signed modulo.&amp;lt;/ref&amp;gt; A function returning the value of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; modulo &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is given in most programming languages with the &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; operator (ie. &amp;lt;tt&amp;gt;x%n&amp;lt;/tt&amp;gt;), and according to the C specification (followed by languages like Python), modulo has the same precedence as multiplication and division, and expressions involving multiple of the same precedence adjacent without brackets will be evaluated left-to-right.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Without modulo or floordiv (only multiplication and division), this is equivalent to division being evaluated before multiplication, as is taught in schools.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Such equalities under the modulo operation are denoted as &amp;lt;tt&amp;gt;a≡b (mod n)&amp;lt;/tt&amp;gt;. For instance, &amp;lt;tt&amp;gt;5≡8 (mod 3)&amp;lt;/tt&amp;gt;, because both of them (after multiples of &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; are subtracted) evaluate to &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;. Alternatively (for integer modulo bases &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;x%n&amp;lt;/tt&amp;gt; is equivalent to taking &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;&amp;#039;s expansion in base &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; and truncating the digits with greater place value than &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;. Modular arithmetic is generally concerned with the behaviour of operations under the modulo operation with a fixed base.&lt;br /&gt;
&lt;br /&gt;
Additional arithmetic rules allow manipulation of expressions involving modulo operations, such as that &amp;lt;tt&amp;gt;x*y%n=(x%n)*(y%n)%n&amp;lt;/tt&amp;gt;, with which many computations involving modulo operators can be evaluated more efficiently than explicitly, such as [https://en.wikipedia.org/wiki/Modular_exponentiation modular exponentiation], where calculating &amp;lt;tt&amp;gt;x**p%n&amp;lt;/tt&amp;gt; allows you to &amp;quot;unravel&amp;quot; the exponentiation into a series of multiplications, and modulo the result by &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; with each successive multiplication.&lt;br /&gt;
&lt;br /&gt;
Beginning with integers &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; (such that &amp;lt;tt&amp;gt;0&amp;lt;=x&amp;lt;n&amp;lt;/tt&amp;gt;) and recursively adding an integer &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and modulo&amp;#039;ing by &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; (ie. setting &amp;lt;tt&amp;gt;x=(x+k)%n&amp;lt;/tt&amp;gt;) will cause &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;&amp;#039;s value to oscillate with period &amp;lt;tt&amp;gt;n/gcd(n,k)&amp;lt;/tt&amp;gt; (equivalently &amp;lt;tt&amp;gt;lcm(n,k)/k&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
For a modulo base &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; and period &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, for there to exist any integers &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; such that recursive addition of &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; has period &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; must be a factor of &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; (meaning &amp;lt;tt&amp;gt;n%p=0&amp;lt;/tt&amp;gt;). These integers &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; are then the set of those &amp;lt;tt&amp;gt;0&amp;lt;k&amp;lt;p&amp;lt;/tt&amp;gt; coprime to &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt;, each multiplied by &amp;lt;tt&amp;gt;n/p&amp;lt;/tt&amp;gt;. The number of such values &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; is then given by &amp;lt;tt&amp;gt;phi(p)&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;phi&amp;lt;/tt&amp;gt; is [https://en.wikipedia.org/wiki/Euler&amp;#039;s_totient_function Euler&amp;#039;s totient function], {{OEIS|A000010}}.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;These can be tabulated by running &amp;lt;tt&amp;gt;print((lambda m: (lambda f: &amp;#039;\n&amp;#039;.join(map(lambda n: &amp;#039;n=&amp;#039;+f(m,n)+&amp;#039;: (\n &amp;#039;+&amp;#039;,\n &amp;#039;.join(map(lambda p: p[1],filter(lambda p: p[0],map(lambda p: (lambda t: (len(t),&amp;#039;p=&amp;#039;+f(m,p)+&amp;#039;: (&amp;#039;+&amp;#039;,&amp;#039;.join(map(str,t))+&amp;#039;)&amp;#039;))(tuple(filter(lambda k: n//__import__(&amp;#039;math&amp;#039;).gcd(n,k)==p,range(n)))),range(1,n+1)))))+&amp;#039;)&amp;#039;,range(m))))(lambda n,k: &amp;#039; &amp;#039;*(len(str(n))-len(str(k)))+str(k)))(16))&amp;lt;/tt&amp;gt; in the Python terminal. The lengths of the tuples, over all values of &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; (instead of only nonzero ones), is the triangular array {{OEIS|A054522}}.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no similar such statement about modular integer multiplication by a constant, because unlike addition of a constant, the structure of its mapping is not invariant across all inputs.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;Also, it is neither injective (such that all numbers &amp;lt;tt&amp;gt;0&amp;lt;=x&amp;lt;n&amp;lt;/tt&amp;gt; produce unique values under multiplication by &amp;lt;tt&amp;gt;k&amp;lt;/tt&amp;gt; followed by modulo by &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;) nor surjective (such that for given &amp;lt;tt&amp;gt;n,k&amp;lt;/tt&amp;gt; every value &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; can have an &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; found such that &amp;lt;tt&amp;gt;k*x%n=y&amp;lt;/tt&amp;gt;). An injective function with a range of outputs equal to that of its inputs (like modular addition of a constant) is also surjective, and together they are bijective, meaning an inverse function can be defined. Modular multiplicative inverses (ie. a number &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; such that &amp;lt;tt&amp;gt;x*y%n=1&amp;lt;/tt&amp;gt;) can be defined where &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; are coprime, and is implemented in Python&amp;#039;s three-argument [https://docs.python.org/3/library/functions.html#pow &amp;lt;tt&amp;gt;pow&amp;lt;/tt&amp;gt;] function.&amp;lt;/ref&amp;gt; Due to this, similarly to cellular automata in finite planes as functions on the set of states, recursively applying a multiplication will cause integers to eventually enter one of several cycles, upon which the period depends.&amp;lt;ref group=&amp;quot;n&amp;quot;&amp;gt;An equivalent program to the previous one (for the cycle obtained by beginning at &amp;lt;tt&amp;gt;x=1&amp;lt;/tt&amp;gt;) is &amp;lt;tt&amp;gt;print((lambda m: (lambda f: &amp;#039;\n&amp;#039;.join(map(lambda n: &amp;#039;n=&amp;#039;+f(m,n)+&amp;#039;: (&amp;#039;+&amp;#039;,&amp;#039;.join((lambda t: map(lambda p: f(m,t.count(p)),range(1,n)))(tuple(map(lambda k: (lambda f: f(f))(lambda f: lambda r,t: (lambda r: t.index(r)+1 if r in t else f(f)(r,(r,)+t))(k*r%n))(1,()),range(1,n)))))+&amp;#039;)&amp;#039;,range(1,m))))(lambda n,k: &amp;#039; &amp;#039;*(len(str(n))-len(str(k)))+str(k)))(16))&amp;lt;/tt&amp;gt;, which generates {{OEIS|A057593}},{{br}}and the number of cycles counting by &amp;lt;tt&amp;gt;print((lambda m: (lambda f: &amp;#039;\n&amp;#039;.join(map(lambda n: &amp;#039;n=&amp;#039;+f(m,n)+&amp;#039;: &amp;#039;+&amp;#039;,&amp;#039;.join(map(lambda k: f(m,(lambda f: f(f))(lambda f: lambda c,i,o,p: (lambda o: o if all(c) else f(f)(c,c.index(0),o,p+1))(o+(c[i]==p)) if c[i] else f(f)(c[:i]+(p,)+c[i+1:],k*i%n,o,p))((0,)*n,0,0,1)),range(n+1))),range(1,m))))(lambda n,k: &amp;#039; &amp;#039;*(len(str(n))-len(str(k)))+str(k)))(24))&amp;lt;/tt&amp;gt; (removing the &amp;lt;tt&amp;gt;k=0&amp;lt;/tt&amp;gt; column returns {{OEIS|A348888}}, which has [https://oeis.org/A348888/a348888.pdf a nice diagram] showing the cycles formed by different &amp;lt;tt&amp;gt;n,k&amp;lt;/tt&amp;gt;).&amp;lt;/ref&amp;gt; Implementations of modular exponentiation to large powers with small modulo bases can be further optimised by detecting the length of the cycle that an exponentiation process enters and finding the phase that it ends in by taking the remaining exponent (upon entry to the cycle) modulo this length, and using it as the index in the cycle.&lt;br /&gt;
&lt;br /&gt;
==Relationship with bitwise operators==&lt;br /&gt;
In programming, where &amp;lt;tt&amp;gt;x,n&amp;lt;/tt&amp;gt; are integer (as is usually necessary for bitwise operators) and &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt; is known to be a power of &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;, because it corresponds with truncating &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;&amp;#039;s &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;-ary expansion to the last digit, and its binary expansion to the last &amp;lt;tt&amp;gt;log_2(n)&amp;lt;/tt&amp;gt; digits, &amp;lt;tt&amp;gt;x%n=x&amp;amp;n-1&amp;lt;/tt&amp;gt;, the latter of which can be more efficient to compute. The Stanford bit-twiddling hacks explain [https://graphics.stanford.edu/~seander/bithacks.html#ModulusDivision division by &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; less than a power of &amp;lt;tt&amp;gt;2&amp;lt;/tt&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
==Notable congruences==&lt;br /&gt;
These provide algebraic reduction steps for forms that can arise generally in modular arithmetic problems.&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Fermat&amp;#039;s_little_theorem Fermat&amp;#039;s little theorem] states that for a prime &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; and other integer &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;c**p≡c (mod p)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Wilson&amp;#039;s_theorem Wilson&amp;#039;s theorem] states that for an integer &amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;(n-1)! ≡ -1 (mod n)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Pólya enumeration theorem]] (through application of a corollary of which, the theorems above can be proven)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references group=&amp;quot;n&amp;quot;&amp;gt;&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://cp4space.files.wordpress.com/2012/09/moda-ch01.pdf Combinatorics I], the first chapter of [[Adam P. Goucher]]&amp;#039;s book, &amp;#039;&amp;#039;Mathematical Olympiad Dark Arts&amp;#039;&amp;#039; (that explains a great deal more about modular arithmetic than this)&lt;br /&gt;
__NOTOC__&lt;br /&gt;
[[Category:Algorithms]]&lt;br /&gt;
[[Category:Mathematical miscellany]]&lt;/div&gt;</summary>
		<author><name>DroneBetter</name></author>
	</entry>
</feed>