<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3%2F04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83</id>
	<title>06-数学相关/04-乘法逆元 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3%2F04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;action=history"/>
	<updated>2026-05-20T22:20:05Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=367&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=367&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:11Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&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;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key my_wiki:diff:1.41:old-366:rev-367 --&gt;
&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=366&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=366&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</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;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key my_wiki:diff:1.41:old-267:rev-366 --&gt;
&lt;/table&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=267&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=267&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:41Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&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;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 16:25的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key my_wiki:diff:1.41:old-266:rev-267 --&gt;
&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=266&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=06-%E6%95%B0%E5%AD%A6%E7%9B%B8%E5%85%B3/04-%E4%B9%98%E6%B3%95%E9%80%86%E5%85%83&amp;diff=266&amp;oldid=prev"/>
		<updated>2026-05-20T16:22:29Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== 前置：快速幂 ==&lt;br /&gt;
&lt;br /&gt;
=== 非递归版 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// a 的 b 次方在模 p 意义下的结果&lt;br /&gt;
int quick_pow(int a, int b, int p)&lt;br /&gt;
{&lt;br /&gt;
    int res = 1;&lt;br /&gt;
    while (b &amp;gt; 0)&lt;br /&gt;
    {&lt;br /&gt;
        if (b % 2 == 1)&lt;br /&gt;
            res = 1LL * res * a % p;&lt;br /&gt;
        b /= 2;&lt;br /&gt;
        a = 1LL * a * a % p;&lt;br /&gt;
    }&lt;br /&gt;
    return res;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 递归版 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int quick_pow(int a, int b, int p)&lt;br /&gt;
{&lt;br /&gt;
    if (b == 0)&lt;br /&gt;
        return 1;&lt;br /&gt;
    int x = quick_pow(a, b / 2, p);&lt;br /&gt;
    if (b % 2 == 0)&lt;br /&gt;
        return 1LL * x * x % p;&lt;br /&gt;
    return 1LL * x * x % p * a % p;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 费马小定理求逆元 ==&lt;br /&gt;
&lt;br /&gt;
当 &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; 是质数时：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a^{-1}\equiv a^{p-2}\pmod p&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// a 在模 p（质数）意义下的逆元&lt;br /&gt;
int inv(int a, int p)&lt;br /&gt;
{&lt;br /&gt;
    return quick_pow(a, p - 2, p);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 扩展欧几里得求逆元 ==&lt;br /&gt;
&lt;br /&gt;
当 &amp;lt;math&amp;gt;\gcd(a,b)=1&amp;lt;/math&amp;gt; 时：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// a 在模 b 意义下的逆元（要求 gcd(a,b)==1）&lt;br /&gt;
int inv(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
    auto [x, y] = exGCD(a, b);&lt;br /&gt;
    // a*x + b*y = 1，所以 a*x === 1 (%b)&lt;br /&gt;
    return (x % b + b) % b;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 线性求逆元 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;O(n)&amp;lt;/math&amp;gt; 预处理 &amp;lt;math&amp;gt;1\sim n&amp;lt;/math&amp;gt; 在模质数 &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; 下的逆元。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;i^{-1}\equiv -\lfloor\frac{p}{i}\rfloor\times (p\bmod i)^{-1}\pmod p&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
inv[1] = 1;&lt;br /&gt;
for (int i = 2; i &amp;lt;= n; i++)&lt;br /&gt;
    inv[i] = (p - p / i) * inv[p % i] % p;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 阶乘的逆元 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// 预处理 1~n 的逆元&lt;br /&gt;
inv[1] = 1;&lt;br /&gt;
for (int i = 2; i &amp;lt;= n; i++)&lt;br /&gt;
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;&lt;br /&gt;
&lt;br /&gt;
// 预处理 1~n 的阶乘的逆元&lt;br /&gt;
// invFact[i] = inv[1]*inv[2]*...*inv[i] = invFact[i-1]*inv[i]&lt;br /&gt;
invFact[0] = invFact[1] = 1;&lt;br /&gt;
for (int i = 2; i &amp;lt;= n; i++)&lt;br /&gt;
    invFact[i] = invFact[i - 1] * inv[i] % MOD;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 常用写法总结 ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! 方法 !! 条件 !! 复杂度&lt;br /&gt;
|-&lt;br /&gt;
| 费马小定理&lt;br /&gt;
| &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; 是质数&lt;br /&gt;
| &amp;lt;math&amp;gt;O(\log p)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 扩欧&lt;br /&gt;
| &amp;lt;math&amp;gt;\gcd(a,p)=1&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;O(\log a)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 线性递推&lt;br /&gt;
| &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; 是质数，求 &amp;lt;math&amp;gt;1\sim n&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;O(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:数学相关]]&lt;br /&gt;
[[Category:三三文档]]&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>