{"id":212,"date":"2026-01-08T19:48:06","date_gmt":"2026-01-08T11:48:06","guid":{"rendered":"https:\/\/jiangqvweihuan.cn\/?p=212"},"modified":"2026-03-21T10:03:41","modified_gmt":"2026-03-21T02:03:41","slug":"%e5%9f%ba%e7%a1%80gcd%e4%b8%8elcm%e6%9c%ac%e8%b4%a8%e4%b8%8e%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/jiangqvweihuan.cn\/index.php\/2026\/01\/08\/%e5%9f%ba%e7%a1%80gcd%e4%b8%8elcm%e6%9c%ac%e8%b4%a8%e4%b8%8e%e4%bd%bf%e7%94%a8\/","title":{"rendered":"\u7b97\u6cd5\u5fc3\u4f20\u00b7\u57fa\u7840gcd\u4e0elcm\u672c\u8d28\u4e0e\u4f7f\u7528"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001gcd<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5f15\u5165<\/h3>\n\n\n\n<p>\u4e00\u7ec4\u6574\u6570\u7684\u516c\u7ea6\u6570\uff0c\u662f\u6307\u540c\u65f6\u662f\u8fd9\u7ec4\u6570\u4e2d\u6bcf\u4e00\u4e2a\u6570\u7684\u7ea6\u6570\u7684\u6570\u3002<\/p>\n\n\n\n<p>\u663e\u7136\uff0c<strong>\u00b11<\/strong>\u662f\u4efb\u610f\u4e00\u7ec4\u6574\u6570\u7684\u516c\u7ea6\u6570\u3002<\/p>\n\n\n\n<p>\u6700\u5927\u516c\u7ea6\u6570\uff08\u4e5f\u79f0\u6700\u5927\u516c\u56e0\u6570\uff0c\u82f1\u6587\u5168\u79f0\u4e3a Greatest Common Divisor\uff0c\u5e38\u7f29\u5199\u4e3a gcd\uff09\u3002\u4e00\u7ec4\u6574\u6570\u7684<strong>\u6700\u5927\u516c\u7ea6\u6570<\/strong>\uff0c\u662f\u6307\u6240\u6709\u516c\u7ea6\u6570\u91cc\u9762<strong>\u6700\u5927<\/strong>\u7684\u4e00\u4e2a\u3002\u5bf9\u4e0d\u5168\u4e3a&nbsp;0\u7684\u6574\u6570&nbsp;\ud835\udc4e,\ud835\udc4f\uff0c\u5c06\u5176\u6700\u5927\u516c\u7ea6\u6570\u8bb0\u4e3a&nbsp;gcd(\ud835\udc4e, \ud835\udc4f)\u3002\u5bf9\u4e0d\u5168\u4e3a&nbsp;0\u7684\u6574\u6570<math data-latex=\"a_1\"><semantics><msub><mi>a<\/mi><mn>1<\/mn><\/msub><annotation encoding=\"application\/x-tex\">a_1<\/annotation><\/semantics><\/math>, \u2026&#8230; ,<math data-latex=\"a_n\"><semantics><msub><mi>a<\/mi><mi>n<\/mi><\/msub><annotation encoding=\"application\/x-tex\">a_n<\/annotation><\/semantics><\/math>\uff0c\u5c06\u5176\u6700\u5927\u516c\u7ea6\u6570\u8bb0\u4e3a&nbsp;gcd(<math data-latex=\"a_1\"><semantics><msub><mi>a<\/mi><mn>1<\/mn><\/msub><annotation encoding=\"application\/x-tex\">a_1<\/annotation><\/semantics><\/math>, &#8230;\u2026 ,<math data-latex=\"a_n\"><semantics><msub><mi>a<\/mi><mi>n<\/mi><\/msub><annotation encoding=\"application\/x-tex\">a_n<\/annotation><\/semantics><\/math>)\uff0c\u5728\u65e0\u4e89\u8bae\u7684\u60c5\u51b5\u4e0b\uff0ca\u548cb\u6700\u5927\u516c\u56e0\u6570\u53ef\u8868\u793a\u4e3a(a, b)\u3002<\/p>\n\n\n\n<p>\u7279\u522b\u7684\uff0c\u4efb\u610f\u4e00\u4e2a\u4e0d\u4e3a\u96f6\u6574\u6570\u548c0\u7684\u6700\u5927\u516c\u7ea6\u6570\u90fd\u662f\u8fd9\u4e2a\u6570\u7684\u7edd\u5bf9\u503c\uff0c\u5e76\u4e14gcd(0, 0)\u6ca1\u6709\u610f\u4e49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.gcd\u7684\u51e0\u79cd\u5b9e\u73b0\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">2.1  \u7a77\u4e3e\u6cd5<\/h4>\n\n\n\n<p>\u5bf9\u4e8e\u521d\u5b66\u8005\u800c\u8a00\uff0c\u6c38\u8fdc\u5b58\u5728\u7740\u66b4\u529b\u679a\u4e3e\u6cd5\u89e3\u51b3\u4efb\u4f55\u95ee\u9898\uff0c\u4e0b\u9762\u662f\u5b9e\u73b0\u4ee3\u7801\u53ca\u6ce8\u91ca\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int gcd(int a, int b) {\n    \/\/ \u5904\u7406\u7279\u6b8a\u60c5\u51b5\uff1a0\u548c\u4efb\u4f55\u6570\u7684GCD\u662f\u53e6\u4e00\u4e2a\u6570\u7684\u7edd\u5bf9\u503c\n    if (a == 0) return b &lt; 0 ? -b : b;\n    if (b == 0) return a &lt; 0 ? -a : a;\n    \n    \/\/ \u53d6\u7edd\u5bf9\u503c\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u5173\u5fc3\u6b63\u516c\u7ea6\u6570\n    a = a &lt; 0 ? -a : a;\n    b = b &lt; 0 ? -b : b;\n    \n    \/\/ \u627e\u5230\u8f83\u5c0f\u7684\u6570\u4f5c\u4e3a\u679a\u4e3e\u4e0a\u9650\n    int limit = (a &lt; b) ? a : b;\n    int gcd = 1;  \/\/ 1\u603b\u662f\u516c\u7ea6\u6570\n    \n    \/\/ \u4ece1\u5230limit\u679a\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u516c\u7ea6\u6570\n    for (int i = 1; i &lt;= limit; ++i) {\n        \/\/ \u68c0\u67e5i\u662f\u5426\u80fd\u540c\u65f6\u6574\u9664a\u548cb\n        if (a % i == 0 &amp;&amp; b % i == 0) {\n            gcd = i;  \/\/ \u66f4\u65b0\u627e\u5230\u7684\u516c\u7ea6\u6570\n        }\n    }\n    \n    return gcd;\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u4e0d\u96be\u53d1\u73b0\u6b64\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8ea\uff0cb\u4e2d\u8f83\u5c0f\u7684\u6570\uff0c\u5373O(min(|a|, |b|))\uff0c\u4e3a<strong>\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6<\/strong>\uff0c\u663e\u7136\u4e0d\u662f\u6700\u4f18\u89e3\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.2 \u7d20\u56e0\u6570\u5206\u89e3\u6cd5<\/h4>\n\n\n\n<p><strong>\u6838\u5fc3\u601d\u60f3<\/strong>\uff1a\u5206\u522b\u5c06\u4e24\u4e2a\u6570\u5206\u89e3\u4e3a\u8d28\u56e0\u6570\u7684\u4e58\u79ef\uff0c\u7136\u540e\u53d6<strong>\u5171\u6709\u8d28\u56e0\u6570\u7684\u6700\u5c0f\u6307\u6570\u5e42\u7684\u4e58\u79ef<\/strong>\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u6570\u5b66\u516c\u5f0f\uff1a\u5982\u679c<math data-latex=\"a = p\u2081^{(e\u2081)} p\u2082^{(e\u2082)} ... p\u2096^{(e\u2096)},b = p\u2081^{(f\u2081)} p\u2082^{(f\u2082)} ... p\u2096^{(f\u2096)}\"><semantics><mrow><mi>a<\/mi><mo>=<\/mo><msubsup><mi>p<\/mi><mn>1<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>e<\/mi><mn>1<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><msubsup><mi>p<\/mi><mn>2<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>e<\/mi><mn>2<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><mi>.<\/mi><mi>.<\/mi><mi>.<\/mi><msubsup><mi>p<\/mi><mi>k<\/mi><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>e<\/mi><mi>k<\/mi><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo>=<\/mo><msubsup><mi>p<\/mi><mn>1<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>f<\/mi><mn>1<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><msubsup><mi>p<\/mi><mn>2<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>f<\/mi><mn>2<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><mi>.<\/mi><mi>.<\/mi><mi>.<\/mi><msubsup><mi>p<\/mi><mi>k<\/mi><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><msub><mi>f<\/mi><mi>k<\/mi><\/msub><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><\/mrow><annotation encoding=\"application\/x-tex\">a = p\u2081^{(e\u2081)} p\u2082^{(e\u2082)} &#8230; p\u2096^{(e\u2096)},b = p\u2081^{(f\u2081)} p\u2082^{(f\u2082)} &#8230; p\u2096^{(f\u2096)}<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p class=\"has-text-align-center\">\u5219<math data-latex=\"gcd(a, b) = p\u2081^{(min(e\u2081, f\u2081))} p\u2082^{(min(e\u2082, f\u2082))} ... p\u2096^{(min(e\u2096, f\u2096))}\"><semantics><mrow><mi>g<\/mi><mi>c<\/mi><mi>d<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><msubsup><mi>p<\/mi><mn>1<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><mi>m<\/mi><mi>i<\/mi><mi>n<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msub><mi>e<\/mi><mn>1<\/mn><\/msub><mo separator=\"true\">,<\/mo><msub><mi>f<\/mi><mn>1<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><msubsup><mi>p<\/mi><mn>2<\/mn><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><mi>m<\/mi><mi>i<\/mi><mi>n<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msub><mi>e<\/mi><mn>2<\/mn><\/msub><mo separator=\"true\">,<\/mo><msub><mi>f<\/mi><mn>2<\/mn><\/msub><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><mi>.<\/mi><mi>.<\/mi><mi>.<\/mi><msubsup><mi>p<\/mi><mi>k<\/mi><mrow><mo form=\"prefix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">(<\/mo><mi>m<\/mi><mi>i<\/mi><mi>n<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msub><mi>e<\/mi><mi>k<\/mi><\/msub><mo separator=\"true\">,<\/mo><msub><mi>f<\/mi><mi>k<\/mi><\/msub><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msubsup><\/mrow><annotation encoding=\"application\/x-tex\">gcd(a, b) = p\u2081^{(min(e\u2081, f\u2081))} p\u2082^{(min(e\u2082, f\u2082))} &#8230; p\u2096^{(min(e\u2096, f\u2096))}<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p><strong>\u57fa\u672c\u53d8\u91cf<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>a, b<\/strong>\uff1a\u4e24\u4e2a\u8981\u6c42\u6700\u5927\u516c\u7ea6\u6570\u7684\u6b63\u6574\u6570<\/li>\n\n\n\n<li><strong>p\u2081, p\u2082, &#8230;, p\u2096<\/strong>\uff1a\u8d28\u56e0\u6570\uff08\u7d20\u6570\uff09\n<ul class=\"wp-block-list\">\n<li>\u6240\u6709\u8d28\u6570\u6309\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u6392\u5217<\/li>\n\n\n\n<li>\u8fd9\u4e9b\u662fa\u548cb\u5206\u89e3\u540e<strong>\u6240\u6709\u51fa\u73b0\u7684\u8d28\u56e0\u6570<\/strong>\u7684\u96c6\u5408<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u6307\u6570\u53d8\u91cf<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>e\u2081, e\u2082, &#8230;, e\u2096<\/strong>\uff1aa\u7684\u8d28\u56e0\u6570\u6307\u6570\n<ul class=\"wp-block-list\">\n<li>e\u2081\u662fa\u4e2d\u8d28\u56e0\u6570p\u2081\u51fa\u73b0\u7684\u6b21\u6570\uff08\u6307\u6570\uff09<\/li>\n\n\n\n<li>e\u2082\u662fa\u4e2d\u8d28\u56e0\u6570p\u2082\u51fa\u73b0\u7684\u6b21\u6570<\/li>\n\n\n\n<li>&#8230;\u4f9d\u6b64\u7c7b\u63a8<\/li>\n\n\n\n<li>\u5982\u679c\u67d0\u4e2a\u8d28\u56e0\u6570\u4e0d\u5728a\u4e2d\uff0c\u5219\u5bf9\u5e94\u7684e\u1d62 = 0<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>f\u2081, f\u2082, &#8230;, f\u2096<\/strong>\uff1ab\u7684\u8d28\u56e0\u6570\u6307\u6570\n<ul class=\"wp-block-list\">\n<li>f\u2081\u662fb\u4e2d\u8d28\u56e0\u6570p\u2081\u51fa\u73b0\u7684\u6b21\u6570<\/li>\n\n\n\n<li>f\u2082\u662fb\u4e2d\u8d28\u56e0\u6570p\u2082\u51fa\u73b0\u7684\u6b21\u6570<\/li>\n\n\n\n<li>&#8230;\u4f9d\u6b64\u7c7b\u63a8<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u6570\u5b66\u539f\u7406<\/strong><\/p>\n\n\n\n<p>\u4e00\u4e2a\u6570\u8981\u540c\u65f6\u6574\u9664a\u548cb\uff0c\u5b83\u7684\u6bcf\u4e2a\u8d28\u56e0\u6570\u7684\u6307\u6570\u4e0d\u80fd\u8d85\u8fc7a\u548cb\u4e2d\u8be5\u8d28\u56e0\u6570\u6307\u6570\u7684<strong>\u8f83\u5c0f\u503c<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u53d6\u6700\u5c0f\u6307\u6570\u7684\u539f\u56e0<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e\u8d28\u56e0\u6570p\u1d62\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u5b83\u5728gcd\u4e2d\u7684\u6307\u6570&gt;min(e\u1d62, f\u1d62)\uff0c\u90a3\u4e48\uff1a\n<ul class=\"wp-block-list\">\n<li>\u8981\u4e48\u4e0d\u80fd\u6574\u9664a\uff08\u5982\u679c\u6307\u6570&gt;e\u1d62\uff09<\/li>\n\n\n\n<li>\u8981\u4e48\u4e0d\u80fd\u6574\u9664b\uff08\u5982\u679c\u6307\u6570&gt;f\u1d62\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u6240\u4ee5\u8981\u4fdd\u8bc1\u6574\u9664\uff0c\u6307\u6570\u5fc5\u987b\u2264min(e\u1d62, f\u1d62)<\/li>\n\n\n\n<li>\u4e3a\u4e86gcd\u6700\u5927\uff0c\u6211\u4eec\u53d6\u7b49\u53f7\uff1a\u6307\u6570=min(e\u1d62, f\u1d62)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4f8b\u5b50\u9a8c\u8bc1<\/strong><\/p>\n\n\n<p>a = 12 = 2\u00b2 \u00d7 3\u00b9<br \/>\nb = 18 = 2\u00b9 \u00d7 3\u00b2<\/p>\n<p>gcd(12, 18) = ?<br \/>\n\u5bf9\u8d28\u56e0\u65702\uff1amin(2, 1) = 1 \u2192 2\u00b9<br \/>\n\u5bf9\u8d28\u56e0\u65703\uff1amin(1, 2) = 1 \u2192 3\u00b9<br \/>\ngcd = 2\u00b9 \u00d7 3\u00b9 = 6 \u2713<\/p>\n\n\n\n<p>\u7ed3\u5408\u4e0b\u9762\u5e26\u6709\u8be6\u7ec6\u6ce8\u91ca\u7684\u4ee3\u7801\u53ef\u4ee5\u7406\u89e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7d20\u56e0\u6570\u5206\u89e3\u6cd5\u6c42\u6700\u5927\u516c\u7ea6\u6570\uff08GCD\uff09\nint gcd(int a, int b) {\n    \/\/ \u5904\u7406\u7279\u6b8a\u60c5\u51b5\u548c\u8d1f\u6570\n    if (a == 0) return abs(b);  \/\/ gcd(0,b)=|b|\n    if (b == 0) return abs(a);  \/\/ gcd(a,0)=|a|\n    \n    a = abs(a);  \/\/ \u8f6c\u4e3a\u6b63\u6570\n    b = abs(b);\n    \n    if (a == b) return a;       \/\/ \u76f8\u7b49\u6570\u5feb\u901f\u8fd4\u56de\n    if (a == 1 || b == 1) return 1;  \/\/ \u5305\u542b1\u7684\u60c5\u51b5\n    \n    int gcd = 1;  \/\/ \u521d\u59cb\u5316\u4e3a1\uff08\u6700\u5c0f\u516c\u7ea6\u6570\uff09\n    \n    \/\/ \u7b2c\u4e00\u9636\u6bb5\uff1a\u63d0\u53d6\u6240\u6709\u516c\u5171\u7684\u56e0\u5b502\n    \/\/ 2\u662f\u552f\u4e00\u7684\u5076\u8d28\u6570\uff0c\u5355\u72ec\u5904\u7406\u53ef\u4f18\u5316\u6027\u80fd\n    while (a % 2 == 0 &amp;&amp; b % 2 == 0) {\n        gcd *= 2;\n        a \/= 2;\n        b \/= 2;\n    }\n    \n    \/\/ \u7b2c\u4e8c\u9636\u6bb5\uff1a\u68c0\u67e5\u5947\u6570\u56e0\u5b50\n    \/\/ \u53ea\u9700\u68c0\u67e5\u5230min(a,b)\u7684\u5e73\u65b9\u6839\uff0c\u56e0\u4e3a\u5927\u4e8e\u5e73\u65b9\u6839\u7684\u56e0\u5b50\u6700\u591a\u53ea\u6709\u4e00\u4e2a\n    for (int i = 3; i * i &lt;= min(a, b); i += 2) {\n        \/\/ \u63d0\u53d6\u6240\u6709\u516c\u5171\u7684\u56e0\u5b50i\n        while (a % i == 0 &amp;&amp; b % i == 0) {\n            gcd *= i;\n            a \/= i;\n            b \/= i;\n        }\n    }\n    \n    \/\/ \u7b2c\u4e09\u9636\u6bb5\uff1a\u5904\u7406\u5927\u4e8e\u5e73\u65b9\u6839\u7684\u516c\u5171\u8d28\u56e0\u6570\n    if (a == b &amp;&amp; a &gt; 1) {\n        gcd *= a;  \/\/ \u8fd9\u662f\u5269\u4f59\u7684\u552f\u4e00\u516c\u5171\u8d28\u56e0\u6570\n    }\n    \n    return gcd;\n}\n\n\/*\n\u7b97\u6cd5\u601d\u60f3\uff1a\n1. \u5206\u522b\u5206\u89e3\u4e24\u4e2a\u6570\u7684\u8d28\u56e0\u6570\n2. \u53d6\u6240\u6709\u516c\u5171\u8d28\u56e0\u6570\u7684\u6700\u5c0f\u6b21\u5e42\u4e58\u79ef\n3. \u4f18\u5316\uff1a\u5355\u72ec\u5904\u7406\u56e0\u5b502\uff0c\u53ea\u68c0\u67e5\u5947\u6570\uff0c\u51cf\u5c11\u5faa\u73af\u6b21\u6570\n\n\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(1)\n\n\u793a\u4f8b\uff1a\ngcd(36,48) = 12\n36 = 2\u00b2\u00d73\u00b2\n48 = 2\u2074\u00d73\n\u516c\u5171\u8d28\u56e0\u6570\uff1a2\u00b2\u00d73 = 12\n*\/<\/code><\/pre>\n\n\n\n<p>\u6b64\u65f6\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO<math data-latex=\"(\\sqrt{min(a,b)})\"><semantics><mrow><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msqrt><mrow><mi>m<\/mi><mi>i<\/mi><mi>n<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\" lspace=\"0em\" rspace=\"0em\">)<\/mo><\/mrow><\/msqrt><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">(\\sqrt{min(a,b)})<\/annotation><\/semantics><\/math>\uff0c\u76f8\u8f83\u7a77\u4e3e\u6cd5\u6709\u6240\u63d0\u5347\uff0c\u4f46\u5728\u5927\u6570\u5904\u7406\u4e0a\u4f9d\u7136\u4e0d\u4f18\u79c0\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u4ee5\u4e0a\u8d28\u6570\uff08\u7d20\u6570\uff09\u7684\u5904\u7406\u6211\u4f1a\u5728\u540e\u9762\u7684\u7bc7\u7ae0\u4e2d\u5355\u72ec\u8be6\u89e3\uff0c\u656c\u8bf7\u671f\u5f85\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\uff08\u8f97\u8f6c\u76f8\u9664\u6cd5\uff09<\/h3>\n\n\n\n<p>\u524d\u9762\u7684\u4e24\u79cd\u65b9\u6cd5\u662f\u4e3a\u4e86\u5e2e\u52a9\u4f60\u66f4\u597d\u7684\u7406\u89e3gcd\uff0c\u8bba\u7b97\u6cd5\u7ade\u8d5b\u4e2d\u6700\u5e38\u7528\u7684\u6c42gcd\u7684\u65b9\u6cd5\u8fd8\u5f97\u662f\u5927\u540d\u9f0e\u9f0e\u7684\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u629b\u5f00\u521a\u624d\u7684\u4e24\u79cd\u65b9\u6cd5\u91cd\u65b0\u601d\u8003\uff0c\u5982\u679c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e24\u4e2a\u6570a\u548cb\uff0c\u600e\u4e48\u6c42gcd(a, b)\u5462\uff1f<\/p>\n\n\n\n<p>\u6211\u4eec\u4e0d\u59a8\u8bbea &gt; b\uff0c\u6211\u4eec\u4e0d\u96be\u53d1\u73b0\uff0c\u5982\u679cb\u662fa\u7684\u4e00\u4e2a\u7ea6\u6570\uff0c\u90a3\u4e48gcd(a, b) = b\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u5206\u6790\u5176\u4ed6\u60c5\u51b5\u5373a\u4e0d\u80fd\u88abb\u6574\u9664\u7684\u60c5\u51b5\uff1a<\/p>\n\n\n\n<p><strong>\u8bc1\u660e<\/strong><\/p>\n\n\n\n<p>\u7ed9\u5b9a\u6574\u6570&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>a<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>\uff08<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><mo>&gt;<\/mo><mn>0<\/mn><\/mrow><\/semantics><\/math>\uff0c<em>b<\/em>&gt;0\uff09\uff0c\u4ee4&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>k<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u4e3a&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>a<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u9664\u4ee5&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u7684\u5546\uff0c<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>c<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u4e3a\u4f59\u6570\uff0c\u5373\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-center\"><math data-latex=\"a=bk+c,0\u2264c&lt;b,\"><semantics><mrow><mi>a<\/mi><mo>=<\/mo><mi>b<\/mi><mi>k<\/mi><mo>+<\/mo><mi>c<\/mi><mo separator=\"true\">,<\/mo><mn>0<\/mn><mo>\u2264<\/mo><mi>c<\/mi><mo>&lt;<\/mo><mi>b<\/mi><mo separator=\"true\">,<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">a=bk+c,0\u2264c&lt;b,<\/annotation><\/semantics><\/math>\u663e\u7136\uff0cc = a % b\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u8bc1\u660e\uff1a\u82e5&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>d<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u662f&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>a<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u7684\u516c\u7ea6\u6570\uff0c\u5219&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>d<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u4e5f\u662f&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>c<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u7684\u516c\u7ea6\u6570<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u4e0d\u59a8\u8bbed\u6574\u9664a\u4e14d\u6574\u9664b\uff0c\u7531 <math data-latex=\"c=a-bk\"><semantics><mrow><mi>c<\/mi><mo>=<\/mo><mi>a<\/mi><mo>\u2212<\/mo><mi>b<\/mi><mi>k<\/mi><\/mrow><annotation encoding=\"application\/x-tex\">c=a-bk<\/annotation><\/semantics><\/math> \u5f97\uff1a<math data-latex=\"\\frac{c}{d} = \\frac{a}{d} - \\frac{b}{d}k\"><semantics><mrow><mfrac><mi>c<\/mi><mi>d<\/mi><\/mfrac><mo>=<\/mo><mfrac><mi>a<\/mi><mi>d<\/mi><\/mfrac><mo>\u2212<\/mo><mfrac><mi>b<\/mi><mi>d<\/mi><\/mfrac><mi>k<\/mi><\/mrow><annotation encoding=\"application\/x-tex\">\\frac{c}{d} = \\frac{a}{d} &#8211; \\frac{b}{d}k<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p>\u56e0\u4e3a <math data-latex=\"\\frac{a}{d}\"><semantics><mfrac><mi>a<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\">\\frac{a}{d}<\/annotation><\/semantics><\/math> \u548c <math data-latex=\"\\frac{b}{d}\"><semantics><mfrac><mi>b<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\">\\frac{b}{d}<\/annotation><\/semantics><\/math> \u5747\u4e3a\u6574\u6570\uff0c\u5219 <math data-latex=\"\\frac{c}{d}\"><semantics><mfrac><mi>c<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\">\\frac{c}{d}<\/annotation><\/semantics><\/math> \u4e5f\u4e00\u5b9a\u4e3a\u6574\u6570\uff0c\u5373d\u6574\u9664c\uff0c\u56e0\u6b64d\u662fb\u548cc\u7684\u516c\u7ea6\u6570\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u8bc1\u660e\uff1a\u82e5&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>d<\/mi><\/mrow><\/semantics><\/math> \u662f&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>c<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u7684\u516c\u7ea6\u6570\uff0c\u5219&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>d<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u4e5f\u662f&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>a<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u7684\u516c\u7ea6\u6570<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u4e0d\u59a8\u8bbed\u6574\u9664b\u4e14d\u6574\u9664c\uff0c\u7531 <math data-latex=\"a = bk + c\"><semantics><mrow><mi>a<\/mi><mo>=<\/mo><mi>b<\/mi><mi>k<\/mi><mo>+<\/mo><mi>c<\/mi><\/mrow><annotation encoding=\"application\/x-tex\">a = bk + c<\/annotation><\/semantics><\/math> \u5f97\uff1a<math data-latex=\" \\frac{a}{d} = \\frac{b}{d}k + \\frac{c}{d}\"><semantics><mrow><mfrac><mi>a<\/mi><mi>d<\/mi><\/mfrac><mo>=<\/mo><mfrac><mi>b<\/mi><mi>d<\/mi><\/mfrac><mi>k<\/mi><mo>+<\/mo><mfrac><mi>c<\/mi><mi>d<\/mi><\/mfrac><\/mrow><annotation encoding=\"application\/x-tex\"> \\frac{a}{d} = \\frac{b}{d}k + \\frac{c}{d}<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p>\u56e0\u4e3a <math data-latex=\"\\frac{b}{d}\"><semantics><mfrac><mi>b<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\">\\frac{b}{d}<\/annotation><\/semantics><\/math> \u548c <math data-latex=\"\\frac{c}{d}\"><semantics><mfrac><mi>c<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\">\\frac{c}{d}<\/annotation><\/semantics><\/math> \u5747\u4e3a\u6574\u6570\uff0c\u5219 <math data-latex=\" \\frac{a}{d}\"><semantics><mfrac><mi>a<\/mi><mi>d<\/mi><\/mfrac><annotation encoding=\"application\/x-tex\"> \\frac{a}{d}<\/annotation><\/semantics><\/math> \u4e5f\u4e00\u5b9a\u4e3a\u6574\u6570\uff0c\u5373d\u6574\u9664a\uff0c\u56e0\u6b64d\u662fa\u548cb\u7684\u516c\u7ea6\u6570\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u7efc\u4e0a\uff0c\u7ed3\u8bba\u4e3aa\u548cb\u7684\u516c\u7ea6\u6570\u96c6\u5408\u4e0eb\u548ca%b\u7684\u516c\u7ea6\u6570\u96c6\u5408\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n\n\n\n<p>\u7ecf\u8fc7\u4ee5\u4e0a\u4e00\u7cfb\u5217\u7684\u6570\u5b66\u63a8\u7406\uff0c\u6211\u4eec\u5f97\u5230\u7ed3\u8bba<\/p>\n\n\n\n<p class=\"has-text-align-center\"><math data-latex=\"gcd(a,b) = gcd(b,a\\,\\,mod\\,\\,b)\"><semantics><mrow><mi>g<\/mi><mi>c<\/mi><mi>d<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mi>g<\/mi><mi>c<\/mi><mi>d<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>b<\/mi><mo separator=\"true\">,<\/mo><mi>a<\/mi><mspace width=\"0.1667em\"><\/mspace><mspace width=\"0.1667em\"><\/mspace><mi>m<\/mi><mi>o<\/mi><mi>d<\/mi><mspace width=\"0.1667em\"><\/mspace><mspace width=\"0.1667em\"><\/mspace><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">gcd(a,b) = gcd(b,a\\,\\,mod\\,\\,b)<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p>\u6709\u4e86\u4ee5\u4e0a\u7ed3\u8bba\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u51fagcd\u7684\u9012\u5f52\u6b27\u51e0\u91cc\u5f97\u7684\u4e09\u76ee\u8fd0\u7b97\u4ee3\u7801\uff0c\u53ea\u9700\u4e00\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int gcd(int a, int b) { return b ? gcd(b, a % b) : a;}<\/code><\/pre>\n\n\n\n<p>\u663e\u7136\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5199\u51fa\u8fed\u4ee3\u6b27\u51e0\u91cc\u5f97\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int gcd(int a, int b) {\n    while (b) {\n        int temp = b;\n        b = a % b;\n        a = temp;\n    }\n    return a;\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e24\u8005\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u5df2\u7ecf\u8fbe\u5230\u6700\u4f18\u89e3\u4e4b\u4e00\uff0c\u5373O<math data-latex=\"(1.44*log_2(min(a,b))\"><semantics><mrow><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mn>1.44<\/mn><mo>\u2217<\/mo><mi>l<\/mi><mi>o<\/mi><msub><mi>g<\/mi><mn>2<\/mn><\/msub><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>m<\/mi><mi>i<\/mi><mi>n<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">(1.44*log_2(min(a,b))<\/annotation><\/semantics><\/math>\u3002<\/p>\n\n\n\n<p>\u7b97\u6cd5\u7ade\u8d5b\u4e2d\u66f4\u63a8\u8350\u4f7f\u7528\u9012\u5f52\u6b27\u51e0\u91cc\u5f97\u4e09\u76ee\u8fd0\u7b97\u4ee3\u7801\uff0c\u5b83\u66f4\u52a0\u7b80\u6d01\uff0c\u540c\u65f6\u5bf9\u4e8eC++17\u53ca\u4ee5\u4e0a\uff08\u666e\u904d\u7684\u7ade\u8d5b\u73af\u5883\uff09\uff0cSTL\u5e93\u4e2d\u7684gcd\u4f7f\u7528\u7684\u662f\u9012\u5f52\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\uff0c\u6240\u4ee5\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662f\u6700\u4f18\u4e4b\u4e00\uff0c\u53ef\u4ee5\u5728\u4e07\u80fd\u5934\u4e0b\u76f4\u63a5\u8c03\u7528gcd(a, b)\u8fd4\u56de\u7684\u503c\u5c31\u662f\u6700\u5927\u516c\u7ea6\u6570\uff0c\u5355\u72ec\u5bf9\u5e94\u7684\u5934\u6587\u4ef6\u662f#include&lt;numeric&gt;\u3002<\/p>\n\n\n\n<p>\u540c\u65f6\u5bf9\u4e8e\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\u8fd8\u6709\u4e24\u4e2a\u6bd4\u8f83\u5e38\u89c1\u7684\u5e94\u7528\u4ee3\u7801\u5982\u4e0b\uff0c\u53ef\u4ee5\u4e86\u89e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> int gcd (int a, int b) {\n    if (b == 0) return a;  \/\/ \u5904\u7406b\u4e3a0\u7684\u60c5\u51b5\n    \n    while (true) {\n        a %= b;\n        if (a == 0) break;\n        \n        b %= a;\n        if (b == 0) {\n            \/\/ \u4ea4\u6362\uff0c\u4f7fgcd\u5728a\u4e2d\n            a ^= b;\n            b ^= a;\n            a ^= b;\n            break;\n        }\n    }\n    return a;  \/\/ \u6216\u8005 return a + b\uff0c\u56e0\u4e3a\u6b64\u65f6b=0\n}\n\n\n\/\/\u4e0b\u9762\u7684\u4ee3\u7801\u4f7f\u7528\u7684\u662f\u6539\u8fdb\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\nint gcd(int a, int b) {    \n    if(b) while((a%=b) &amp;&amp; (b%=a));  \/\/ \u53cc\u5411\u53d6\u6a21\uff0c\u5229\u7528\u77ed\u8def    \n    return a+b;  \/\/ \u7ed3\u675f\u65f6\u5fc5\u6709\u4e00\u4e2a\u4e3a0\uff0c\u548c\u5373\u4e3agcd\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001lcm<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5f15\u5165<\/h3>\n\n\n\n<p>\u6700\u5c0f\u516c\u500d\u6570\uff08\u82f1\u6587\u7f29\u5199\u4e3alcm\uff09\uff0c\u5c31\u662f\u6307\u5bf9\u4e8e2\u4e2a\u6570a\u548cb\uff0c\u5b83\u4eec\u7684\u516c\u500d\u6570\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\uff0c\u62ff100\u548c75\u4e3e\u4f8b\uff0c\u5b83\u4eec\u7684\u516c\u500d\u6570\u6709<code>300 600 900...<\/code>\uff0c\u5176\u4e2d\u6700\u5c0f\u7684\u662f300\uff0c\u6240\u4ee5100\u548c75\u7684\u6700\u5c0f\u516c\u500d\u6570\u4e3a300\uff0ca\u548cb\u7684\u6700\u5c0f\u516c\u500d\u6570\u5728\u65e0\u4e89\u8bae\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u8868\u793a\u4e3a[a, b]\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.lcm\u7684\u5b9e\u73b0\u65b9\u5f0f<\/h3>\n\n\n\n<p>\u5f53\u4f60\u719f\u7ec3\u638c\u63e1gcd\u540e\uff0clcm\u5c31\u4f1a\u663e\u5f97\u5f02\u5e38\u7684\u7b80\u5355\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u4e24\u4e2a\u6574\u6570a\uff0cb\u800c\u8a00\uff0c<\/p>\n\n\n\n<p class=\"has-text-align-center\"><math data-latex=\"a*b = lcm(a,b)*gcd(a,b)\"><semantics><mrow><mi>a<\/mi><mo>\u2217<\/mo><mi>b<\/mi><mo>=<\/mo><mi>l<\/mi><mi>c<\/mi><mi>m<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>\u2217<\/mo><mi>g<\/mi><mi>c<\/mi><mi>d<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">a*b = lcm(a,b)*gcd(a,b)<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p>\u56e0\u6b64lcm\u4ee3\u7801\u5c31\u53ef\u4ee5\u5728\u6709gcd\u51fd\u6570\u4e4b\u540e\u76f4\u63a5\u4f7f\u7528\uff0c\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int lcm(int a, int b) {\n\treturn a \/ gcd(a, b) * b; \/\/\u9632\u6b62\u6ea2\u51fa\n\t\/\/ gcd(int a,int b) \u5fc5\u9700\u88ab\u5b9a\u4e49\u6216\u58f0\u660e\u8fc7\n}<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u4e5f\u53ef\u4ee5\u4f7f\u7528#include&lt;numeric&gt;\u6216\u8005\u4e07\u80fd\u5934\u540e\u8c03\u7528STL\u5e93\u4e2d\u7684lcm\uff0c\u548c\u4e0a\u9762gcd\u76f8\u540c\uff0c\u4e5f\u662f\u6781\u5feb\u7684\u89e3\u7684\u4e00\u79cd\uff0c\u6bd4\u5982\u6574\u6570a\u548cb\u7684\u6700\u5c0f\u516c\u500d\u6570\u503c\u5c31\u4e3alcm(a, b)\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u88f4\u8700\u5b9a\u7406<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5f15\u5165<\/h3>\n\n\n\n<p>\u88f4\u8700\u5b9a\u7406\uff08B\u00e9zout&#8217;s&nbsp;lemma\uff09\u662f\u6570\u8bba\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u5b9a\u7406\uff0c\u8868\u660e\u5bf9\u4e8e\u4efb\u610f\u4e24\u4e2a\u6574\u6570&nbsp;<math><semantics><mrow><mi>a<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math><semantics><mrow><mi>b<\/mi><\/mrow><\/semantics><\/math>\uff0c\u5b58\u5728\u6574\u6570&nbsp;<math><semantics><mrow><mi>x<\/mi><\/mrow><\/semantics><\/math>&nbsp;\u548c&nbsp;<math><semantics><mrow><mi>y<\/mi><\/mrow><\/semantics><\/math>\uff0c\u4f7f\u5f97&nbsp;<math><semantics><mrow><mi>a<\/mi><mi>x<\/mi><mo>+<\/mo><mi>b<\/mi><mi>y<\/mi><mo>=<\/mo><mi>gcd<\/mi><mo>\u2061<\/mo><mo stretchy=\"false\">(<\/mo><mi>a<\/mi><mo separator=\"true\">,<\/mo><mi>b<\/mi><mo stretchy=\"false\">)<\/mo><\/mrow><\/semantics><\/math>\u3002<\/p>\n\n\n\n<p>\u63a8\u8bba\uff1a\u6574\u6570a\u548cb\u4e92\u7d20\uff0c\u5f53\u4e14\u4ec5\u5f53\u5f53\u524d\u5b58\u5728\u6574\u6570x\u4e0ey\u4f7f\u5f97ax+by=1\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u4f8b\u9898\u5f85\u6211\u6709\u65f6\u95f4\u53d1\u6398&#8230;&#8230;<\/p>\n\n\n\n<p>ok\uff0c\u4ee5\u4e0a\u5c31\u662fgcd\u548clcm\u6240\u6709\u7684\u57fa\u7840\u5185\u5bb9\u4e86\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u597d\u597d\u638c\u63e1\uff0c\u4ee5\u540e\u5bf9\u4e8e\u8fdb\u9636\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\u548c\u5176\u4ed6\u76f8\u5173\u8fdb\u9636\u7b97\u6cd5\u6211\u60f3\u7ed3\u5408\u7740\u5177\u4f53\u9898\u76ee\u6765\u89e3\u51b3\u8bb2\u89e3\u3002\u65e0\u8bba\u5982\u4f55\uff0c\u77e5\u8bc6\u5e38\u770b\u5e38\u65b0\uff0c\u4e0b\u7bc7\u6587\u7ae0\u89c1\u55bd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u7ecf\u5178\u4f8b\u9898<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.luogu.com.cn\/problem\/P1072\">P1072 [NOIP 2009 \u63d0\u9ad8\u7ec4] Hankson \u7684\u8da3\u5473\u9898 &#8211; \u6d1b\u8c37<\/a><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001gcd 1.\u5f15\u5165 \u4e00\u7ec4\u6574\u6570\u7684\u516c\u7ea6\u6570\uff0c\u662f\u6307\u540c\u65f6\u662f\u8fd9\u7ec4\u6570\u4e2d\u6bcf\u4e00\u4e2a\u6570\u7684\u7ea6\u6570\u7684\u6570\u3002 \u663e\u7136\uff0c\u00b11\u662f\u4efb\u610f\u4e00\u7ec4\u6574\u6570\u7684\u516c\u7ea6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":156,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,15,12],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-article","category-algorithm-template","category-programming-algorithm-road"],"_links":{"self":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":15,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/212\/revisions\/353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media\/156"}],"wp:attachment":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}