<?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%2F02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0</id>
	<title>06-数学相关/02-最大公因数与最小公倍数 - 版本历史</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%2F02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0"/>
	<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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;action=history"/>
	<updated>2026-05-20T23:10:22Z</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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=363&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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=363&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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&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;2&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;/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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=362&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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=362&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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&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;2&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;/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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=263&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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=263&amp;oldid=prev"/>
		<updated>2026-05-20T16:25:39Z</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;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&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;2&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;/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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=262&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/02-%E6%9C%80%E5%A4%A7%E5%85%AC%E5%9B%A0%E6%95%B0%E4%B8%8E%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0&amp;diff=262&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;
== 最大公因数（GCD） ==&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 gcd(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
    if (b == 0)&lt;br /&gt;
        return a;&lt;br /&gt;
    return gcd(b, a % 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;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int gcd(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
    while (b)&lt;br /&gt;
    {&lt;br /&gt;
        int t = a % b;&lt;br /&gt;
        a = b;&lt;br /&gt;
        b = t;&lt;br /&gt;
    }&lt;br /&gt;
    return a;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ 内置函数 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
cout &amp;lt;&amp;lt; __gcd(a, b); // 比赛时可以用&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 最小公倍数（LCM） ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\operatorname{lcm}(a,b)=\frac{a\times b}{\gcd(a,b)}&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;
int lcm(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
    return a / gcd(a, 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;ax+by=\gcd(a,b)&amp;lt;/math&amp;gt; 的一组整数解 &amp;lt;math&amp;gt;(x,y)&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;
// 返回 ax+by=gcd(a,b) 的解 (x,y)&lt;br /&gt;
pair&amp;lt;int, int&amp;gt; exGCD(int a, int b)&lt;br /&gt;
{&lt;br /&gt;
    if (b == 0)&lt;br /&gt;
        return {1, 0};&lt;br /&gt;
    auto [xx, yy] = exGCD(b, a % b);&lt;br /&gt;
    return {yy, xx - a / b * yy};&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
引用版本（返回 gcd）：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int exGcd(int a, int b, int &amp;amp;x, int &amp;amp;y)&lt;br /&gt;
{&lt;br /&gt;
    if (b == 0)&lt;br /&gt;
    {&lt;br /&gt;
        x = 1, y = 0;&lt;br /&gt;
        return a;&lt;br /&gt;
    }&lt;br /&gt;
    int xx, yy;&lt;br /&gt;
    int gcd = exGcd(b, a % b, xx, yy);&lt;br /&gt;
    x = yy;&lt;br /&gt;
    y = xx - (a / b) * yy;&lt;br /&gt;
    return gcd;&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;Ax+By=C&amp;lt;/math&amp;gt; 的解 &amp;lt;math&amp;gt;x_0,y_0&amp;lt;/math&amp;gt; 后，通解为：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x=x_0+\frac{B}{\gcd(A,B)}\cdot k&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;y=y_0-\frac{A}{\gcd(A,B)}\cdot k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 更多数的 GCD/LCM ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
int ans = a[1];&lt;br /&gt;
for (int i = 2; i &amp;lt;= n; i++)&lt;br /&gt;
    ans = gcd(ans, a[i]);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;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>