{"id":289,"date":"2024-06-17T17:29:00","date_gmt":"2024-06-17T09:29:00","guid":{"rendered":"https:\/\/www.nenuacm.top\/?p=289"},"modified":"2024-06-17T17:38:36","modified_gmt":"2024-06-17T09:38:36","slug":"%e6%b5%85%e8%b0%88gcd%e5%92%8clcm","status":"publish","type":"post","link":"https:\/\/www.nenuacm.top\/index.php\/2024\/06\/17\/%e6%b5%85%e8%b0%88gcd%e5%92%8clcm\/","title":{"rendered":"\u6d45\u8c08GCD\u548cLCM"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>GCD\uff08\u6700\u5927\u516c\u7ea6\u6570\uff09\u548cLCM\uff08\u6700\u5927\u516c\u500d\u6570\uff09\u90fd\u662f\u5927\u5bb6\u5f88\u719f\u6089\u7684\u4e1c\u897f\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u57fa\u672c\u6982\u5ff5\uff0c\u800c\u662f\u6d45\u8c08\u4e00\u4e0bGCD\u548cLCM\u6240\u5177\u6709\u7684\u4e00\u4e9b\u6027\u8d28\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b97\u6570\u57fa\u672c\u5b9a\u7406<\/h2>\n\n\n\n<p>\u4efb\u4f55\u4e00\u4e2a\u5927\u4e8e1\u7684\u81ea\u7136\u6570 N,\u5982\u679cN\u4e0d\u4e3a\u8d28\u6570\uff0c\u90a3\u4e48N\u53ef\u4ee5\u552f\u4e00\u5206\u89e3\u6210\u6709\u9650\u4e2a\u8d28\u6570\u7684\u4e58\u79ef$N=P_{1}^{a_{1}}P_{2}^{a_{2}}P_{3}^{a_{3}}&#8230;&#8230;P_{n}^{a_{n}}$\uff0c\u8fd9\u91cc$P_{1}&lt;P_{2}&lt;P_{3}&#8230;&#8230;&lt;P_{n}$\u5747\u4e3a\u8d28\u6570\uff0c\u5176\u4e2d\u6307\u6570$a_{i}$\u662f\u6b63\u6574\u6570\u3002<\/p>\n\n\n\n<p>\u7279\u522b\u7684\u5bf9\u4e8e$N = 1$\u7684\u65f6\u5019\u663e\u7136\u6709$1 = 1 \\cdot P_{1}^{0}P_{2}^{0}P_{3}^{0}&#8230;&#8230;P_{n}^{0}$\uff0c\u4e0d\u59a8\u770b\u4f5c\u662f\u4efb\u610f\u8d28\u6570\u76840\u6b21\u5e42\u7684\u4e58\u79ef\uff0c\u5bf9\u4e8eN\u5c5e\u4e8e\u8d28\u6570\u7684\u65f6\u5019\u663e\u7136\u6709$N = N^{1}$<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8d28\u56e0\u6570\u5206\u89e3<\/h2>\n\n\n\n<p>\u7531\u7b97\u6570\u57fa\u672c\u5b9a\u7406\u6211\u4eec\u5c31\u53ef\u4ee5\u5f88\u5bb9\u6613\u5f97\u5230\u8d28\u56e0\u6570\u5206\u89e3\u7684\u7b97\u6cd5\uff0c\u5373\u4ece2\u5f00\u59cb\u9010\u4e2a\u679a\u4e3e\u8d28\u56e0\u6570\uff0c\u56e0\u4e3a\u8d28\u56e0\u6570\u7684\u5e42\u6b21\u53ef\u80fd\u4f1a\u5927\u4e8e1\u6240\u6709\u6211\u4eec\u5c31\u5bf9\u6570N\u4e00\u76f4\u9664\u5230\u4e0d\u80fd\u88ab\u6574\u9664\u4e3a\u6b62\uff0c\u7ee7\u7eed\u679a\u4e3e\u4e0b\u4e00\u4e2a\u8d28\u56e0\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vector&lt;int> factor;\nvoid factorization(int x){\n \u00a0 \u00a0int k = 2;\n \u00a0 \u00a0while(x > 1){\n \u00a0 \u00a0 \u00a0 \u00a0if(x % k == 0){\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0factor.push_back(k);\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0x \/= k;\n \u00a0 \u00a0 \u00a0  }else k++;\n \u00a0  }\n}<\/code><\/pre>\n\n\n\n<p>\u7b97\u6cd5\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a$O(n^{\\frac{1}{4}})$\uff0c\u7ec6\u5fc3\u7684\u540c\u5b66\u53ef\u80fd\u4e00\u773c\u5c31\u770b\u5230\u4e86\u4e00\u79cd\u6bd4\u8f83\u6781\u7aef\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662fN\u672c\u8eab\u5c31\u4e3a\u8d28\u6570\u7684\u60c5\u51b5\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u590d\u6742\u5ea6\u663e\u7136\u662f$O(n)$\uff0c\u6240\u6709\u5f88\u591a\u65f6\u5019\u6211\u4eec\u9700\u8981\u5148\u5bf9$N$\u5224\u65ad\u4e00\u4e0b\u662f\u5426\u662f\u8d28\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u91cd\u65b0\u8ba4\u8bc6GCD<\/h2>\n\n\n\n<p>\u5047\u8bbe\u6709\u6570$a$\u548c\u6570$b$\uff0c\u5176\u4e2d<\/p>\n\n\n\n<p>$a = P_{1}^{1}P_{2}^{2}P_{3}^{2}$<\/p>\n\n\n\n<p>$b = P_{2}^{1}P_{3}^{2}P_{4}^{1}$<\/p>\n\n\n\n<p>\u6b64\u65f6\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3a\u548cb\u5177\u4f53\u662f\u591a\u5c11\uff0c\u80fd\u540c\u65f6\u6574\u9664$a$\u548c$b$\u7684\u7684\u6570\u663e\u7136\u662f$a$\u6216\u8005$b$\u4e2d\u7684\u4e00\u4e9b\u8d28\u56e0\u6570\u7684\u4e58\u79ef\uff0c$a$\u548c$b$\u6700\u591a\u7684\u5171\u540c\u7684\u8d28\u56e0\u6570\u662f$P_{2}^{1}P_{3}^{2}$\uff0c\u5bf9$a$\u548c$b$\u540c\u65f6\u9664\u4ee5$P_{2}^{1}P_{3}^{2}$\u4e4b\u540e\u663e\u7136\u6ca1\u6709\u5171\u540c\u8d28\u56e0\u6570\u4e86\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u6700\u5927\u516c\u7ea6\u6570\u4e3a$P_{2}^{1}P_{3}^{2}$<\/p>\n\n\n\n<p>$lcm$\u5c31\u662f\u5171\u540c\u8d28\u56e0\u6570\u548c\u4e0d\u540c\u8d28\u56e0\u6570\u7684\u4e58\u79ef\uff0c\u5176\u4e2d\u5171\u540c\u8d28\u56e0\u6570\u4e2d\u6bcf\u4e2a\u8d28\u56e0\u6570\u7684\u6b21\u6570\u53d6\u6b21\u6570\u8f83\u9ad8\u7684\u90a3\u4e2a\u4e00\uff0c$lcm(a, b) = P_{1}^{1}P_{2}^{2}P_{3}^{2}P_{4}^{1}$<\/p>\n\n\n\n<p>\u8fd9\u4e5f\u4ece\u4e00\u4e2a\u5f88\u597d\u7684\u89d2\u5ea6\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48$lcm(a,b) = a \\cdot b \/ gcd(a, b)$<\/p>\n\n\n\n<p>\u8bfb\u8005\u53ef\u4ee5\u81ea\u5df1\u53bb\u9a8c\u8bc1\u4e00\u4e0b\u7ed3\u8bba\u7684\u6b63\u786e\u6027\uff0c\u5bf9\u4e8e \u8fd9\u4e00\u6027\u8d28\u6709\u5f88\u591a\u7684\u5999\u7528\uff0c\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u601d\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GCD\uff08\u6700\u5927\u516c\u7ea6\u6570\uff09\u548cLCM\uff08\u6700\u5927\u516c\u500d\u6570\uff09\u90fd\u662f\u5927\u5bb6\u5f88\u719f\u6089\u7684\u4e1c\u897f\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u57fa\u672c\u6982\u5ff5\uff0c\u800c\u662f\u6d45\u8c08\u4e00\u4e0bGCD\u548cLC [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-wushuang"],"_links":{"self":[{"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":13,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/posts\/289\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nenuacm.top\/index.php\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}