{"id":10007067,"date":"2023-01-10T23:33:25","date_gmt":"2023-01-10T15:33:25","guid":{"rendered":"https:\/\/ityet.com\/?p=10007067"},"modified":"2023-01-10T23:33:25","modified_gmt":"2023-01-10T15:33:25","slug":"stackoverflow-%e6%8f%90%e9%97%ae%ef%bc%9a%e8%ae%a1%e7%ae%97%e4%b8%a4%e4%b8%aa%e6%95%b4%e6%95%b0%e7%9a%84%e6%9c%80%e5%b0%8f%e5%85%ac%e5%80%8d%e6%95%b0%e7%9a%84%e6%9c%80%e6%9c%89%e6%95%88","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10007067","title":{"rendered":"stackoverflow \u63d0\u95ee\uff1a\u201c\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\u7684\u6700\u6709\u6548\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f\u201d"},"content":{"rendered":"<p>\u4f5c\u8005\uff1a\u5c0f\u5085\u54e5<br \/>\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=y5oyPgMYQyqu%2Fq6dKw%2BK2g%3D%3D.h5WxpY5ZskkIx4923FmnYRbGx%2Be7a3AVbYR193IN1GI%3D\" rel=\"nofollow\">https:\/\/bugstack.cn<\/a><br \/>\u6e90\u7801\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=t5Meo31LUBqFuB8JFHpoTw%3D%3D.FTCp158%2BcIBeHoxfcVeHpPRu9jH4vepBh3Y3EwI7sAase1IzGEyc2LF2SgmwMkp6\" rel=\"nofollow\">https:\/\/github.com\/fuzhengwei&#8230;<\/a><\/p>\n<blockquote><p>\u6c89\u6dc0\u3001\u5206\u4eab\u3001\u6210\u957f\uff0c\u8ba9\u81ea\u5df1\u548c\u4ed6\u4eba\u90fd\u80fd\u6709\u6240\u6536\u83b7\uff01\ud83d\ude04<\/p><\/blockquote>\n<h2>\u4e00\u3001\u524d\u8a00<\/h2>\n<p>\u563f\uff0c\u5c0f\u5085\u54e5\u600e\u4e48\u7a81\u7136\u8bb2\u5230\u6700\u5927\u516c\u7ea6\u6570\u4e86\uff1f<\/p>\n<p>\u8fd9\u4e48\u60f3\u4f60\u80af\u5b9a\u662f\u6ca1\u6709\u597d\u597d\u9605\u8bfb\u524d\u9762\u7ae0\u8282\u4e2d\u5c0f\u5085\u54e5\u8bb2\u5230\u7684<a href=\"https:\/\/link.segmentfault.com\/?enc=lu4zeITXGZGyEVpDNJaipQ%3D%3D.xjRjzMNEX2Mgc8bWPbC5FrJzT1aToy%2F1lIpyhv94emhrFCa0G8MprIrcZ9pgrZYA0f9hcwy0a%2BqYUUuGwFfo5JCkkKz6VsmFK3hJ5Pau9no%3D\" rel=\"nofollow\">RSA\u7b97\u6cd5<\/a>\uff0c\u5bf9\u4e8e\u4e0e\u6b27\u62c9\u7ed3\u679c\u8ba1\u7b97\u7684\u4e92\u4e3a\u8d28\u6570\u7684\u516c\u94a5e\uff0c\u5176\u5b9e\u5c31\u9700\u8981\u4f7f\u7528\u5230\u8f97\u8f6c\u76f8\u9664\u6cd5\u6765\u8ba1\u7b97\u51fa\u6700\u5927\u516c\u7ea6\u6570\u3002<\/p>\n<p>\u653e\u5fc3\uff0c\u4f60\u6240\u6709\u5199\u7684\u4ee3\u7801\uff0c\u90fd\u662f\u5bf9\u6570\u5b66\u903b\u8f91\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u65e0\u975e\u662f\u96be\u6613\u4e0d\u540c\u7f62\u4e86\u3002\u6240\u4ee5\u5982\u679c\u4f60\u771f\u7684\u60f3\u5b66\u597d\u7f16\u7a0b\u601d\u7ef4\u800c\u4e0d\u53ea\u662fCRUD\uff0c\u90a3\u5c31\u8981\u628a\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u903b\u8f91\u7b49\u6839\u57fa\u6253\u7262\u3002<\/p>\n<h2>\u4e8c\u3001\u77ed\u9664\u6cd5<\/h2>\n<p>\u65e2\u7136\u90fd\u8bf4\u5230\u8fd9\u4e86\uff0c\u90a3\u4f60\u8fd8\u8bb0\u5f97\u600e\u4e48\u8ba1\u7b97\u6700\u5927\u516c\u7ea6\u6570\u5417\uff0c\u6b7b\u9b3c\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043300062\" alt=\"img\" title=\"img\" loading=\"lazy\"><\/p>\n<p>\u4ee5\u4e0a\u8fd9\u79cd\u65b9\u5f0f\u5c31\u662f\u6211\u4eec\u5728\u4e0a\u5b66\u9636\u6bb5\u5b66\u4e60\u7684\uff0c\u8fd9\u79cd\u8ba1\u7b97\u65b9\u5f0f\u53eb\u505a\u77ed\u9664\u6cd5\u3002<\/p>\n<p><strong>\u77ed\u9664\u6cd5<\/strong>\uff1a\u662f\u7b97\u672f\u4e2d\u9664\u6cd5\u7684\u7b97\u6cd5\uff0c\u5c06\u9664\u6cd5\u8f6c\u6362\u6210\u4e00\u8fde\u4e32\u7684\u8fd0\u7b97\u3002\u77ed\u9664\u6cd5\u662f\u7531\u957f\u9664\u6cd5\u7b80\u5316\u800c\u6765\uff0c\u5f53\u4e2d\u4f1a\u7528\u5230\u5fc3\u7b97\uff0c\u56e0\u6b64\u9664\u6570\u8f83\u5c0f\u7684\u9664\u6cd5\u6bd4\u8f83\u9002\u7528\u77ed\u9664\u6cd5\u3002\u5bf9\u5927\u90e8\u5206\u7684\u4eba\u800c\u8a00\uff0c\u82e5\u9664\u4ee512\u621612\u4ee5\u4e0b\u7684\u6570\uff0c\u53ef\u4ee5\u7528\u8bb0\u5fc6\u4e2d\u4e58\u6cd5\u8868\u7684\u5185\u5bb9\uff0c\u7528\u5fc3\u7b97\u6765\u8fdb\u884c\u77ed\u9664\u6cd5\u3002\u4e5f\u6709\u4e9b\u4eba\u53ef\u4ee5\u5904\u7406\u9664\u6570\u66f4\u5927\u7684\u77ed\u9664\u6cd5\u3002\u2014\u2014 <a href=\"https:\/\/link.segmentfault.com\/?enc=jSO9%2Ff7AZHYuJ0BA%2BM1ZGg%3D%3D.D1EGLv3HHTr9kx%2FN8wwmCEqhcvUYUzoVgeQgWw8WnlxQ1lrH962sJSqsZxsE3WTm\" rel=\"nofollow\">\u6765\u81ea\u7ef4\u57fa\u767e\u79d1<\/a><\/p>\n<h2>\u4e09\u3001\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5<\/h2>\n<p>\u77ed\u9664\u6cd5\u80fd\u89e3\u51b3\u8ba1\u7b97\u6700\u5927\u516c\u7ea6\u6570\u7684\u95ee\u9898\uff0c\u4f46\u653e\u5230\u7a0b\u5e8f\u7f16\u5199\u4e2d\u603b\u662f\u5f88\u522b\u626d\uff0c\u603b\u4e0d\u80fd\u4e00\u4e2a\u4e2a\u6570\u5b57\u53bb\u8bd5\u7b97\uff0c\u8fd9\u5c31\u663e\u5f97\u5f88\u95f9\u633a\u3002\u5176\u5b9e\u9664\u4e86\u77ed\u9664\u6cd5\u8fd8\u6709\u4e00\u79cd\u662f\u8ba1\u7b97\u516c\u7ea6\u6570\u7684\u529e\u6cd5\uff0c\u53eb\u505a\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5\u3002<\/p>\n<p><strong>\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5<\/strong>\uff1a\u662f\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\uff08\u6570\u5b57\uff09\u7684\u6700\u5927\u516c\u7ea6\u6570\u3010GCD(Greatest Common Divisor)\u3011\u7684\u6709\u6548\u65b9\u6cd5\uff0c\u5373\u80fd\u5c06\u5b83\u4eec\u6574\u9664\u800c\u65e0\u4f59\u6570\u7684\u6700\u5927\u6570\u3002\u5b83\u4ee5\u53e4\u5e0c\u814a\u6570\u5b66\u5bb6 \u6b27\u51e0\u91cc\u5f97\u7684\u540d\u5b57\u547d\u540d\uff0c\u6b27\u51e0\u91cc\u5fb7\u5728\u4ed6\u7684\u51e0\u4f55\u539f\u672c\uff08\u7ea6\u516c\u5143\u524d 300 \u5e74\uff09\u4e2d\u9996\u6b21\u63cf\u8ff0\u4e86\u5b83\u3002\u5b83\u662f\u7b97\u6cd5\u7684\u793a\u4f8b\uff0c\u662f\u6839\u636e\u660e\u786e\u5b9a\u4e49\u7684\u89c4\u5219\u6267\u884c\u8ba1\u7b97\u7684\u5206\u6b65\u8fc7\u7a0b\uff0c\u5e76\u4e14\u662f\u5e38\u7528\u7684\u6700\u53e4\u8001\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u51cf\u5c11\u5206\u6570\u5230\u4ed6\u4eec\u7684\u6700\u7b80\u5355\u7684\u5f62\u5f0f\uff0c\u5e76\u4e14\u662f\u8bb8\u591a\u5176\u4ed6\u6570\u8bba\u548c\u5bc6\u7801\u8ba1\u7b97\u7684\u4e00\u90e8\u5206\u3002\u2014\u2014 <a href=\"https:\/\/link.segmentfault.com\/?enc=tdVpjLnxZ89uPvS1fckuDg%3D%3D.oRGpDo8mu9wOPTqmqk3rq8npY6a6rGBrvHTqLwcajUFZKWEMv2xuS2bnwOFeIVKc\" rel=\"nofollow\">\u6765\u81ea\u7ef4\u57fa\u767e\u79d1<\/a><\/p>\n<p>GCD\uff0c\u4ee3\u8868\u4e86\u4e24\u4e2a\u6570\u5b57\u7684\u6700\u5927\u516c\u7ea6\u6570\uff0cGCD(X,Y) = Z\uff0c\u90a3\u4e48\u5c31\u8868\u793a X \u548c Y \u7684\u6700\u5927\u516c\u7ea6\u6570\u662f Z\u3002\u7531\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5\u7ed9\u51fa GCD(X,Y) = GCD(Y,XmodY) \u2014\u2014 mod \u8868\u793a\u6c42\u6a21\u8ba1\u7b97\u4f59\u6570\u3002<\/p>\n<p>\u5176\u5b9e\u7b80\u5355\u6765\u8bf4\u5c31\u662f\uff0cX\u548cY\u7684\u516c\u7ea6\u6570\u662fZ\uff0c\u90a3\u4e48Y\u548cZ\u7684\u516c\u7ea6\u6570\u4e5f\u662fZ\u300224\u548c18\u7684\u6700\u5927\u516c\u7ea6\u6570\u662f6\uff0c\u90a3\u4e4818\u548c6\u7684\u516c\u7ea6\u6570\u4e5f\u662f6\u3002\u563f\uff0c\u5c31\u8fd9\u4e48\u4e00\u4e2a\u4e8b\u3002\u4f46\u5c31\u56e0\u4e3a\u6709\u4e86\u8fd9\u4e00\u6837\u4e00\u6761\u63a8\u8bba\uff0c\u8ba9\u7f16\u7a0b\u4ee3\u7801\u53d8\u5f97\u4f18\u96c5\u8212\u670d\uff0c\u53ea\u9700\u8981\u4e0d\u65ad\u5730\u5c06X\u3001Y\u4e24\u6570\u4f5c\u5dee\uff0c\u5c31\u80fd\u8ba1\u7b97\u6700\u5927\u516c\u7ea6\u6570\u3002<\/p>\n<p>\ud83d\ude02 \u8fd9\u8ba9\u5c0f\u5085\u54e5\u60f3\u8d77\uff0c\u591a\u5e74\u524d\u4e0a\u5b66\u65f6\u5019\uff0c\u6211\u4e5f\u7ed9\u51fa\u8fc7\u4e00\u6761\u63a8\u8bba\uff1b\u201d\u4efb\u610f\u4e00\u7ec4\u6240\u80fd\u6784\u6210\u7b49\u5dee\u6570\u5217\u7684\u4e09\u4e2a\u6570\u5b57\uff0c\u6240\u80fd\u7ec4\u5408\u51fa\u6765\u7684\u4e00\u4e2a\u4e09\u4f4d\u6570\uff0c\u90fd\u80fd\u88ab3\u6574\u9664\u3002\u201c \u4f8b\u5982\uff1a\u7b49\u5dee\u6570\u5217 <code>16<\/code>\u3001<code>31<\/code>\u3001<code>46<\/code> \u7ec4\u5408\u6210\u4e09\u4f4d\u6570 <code>463116<\/code> \u6216\u8005 <code>461631<\/code> \u90fd\u80fd\u88ab3\u6574\u9664\u3002<\/p>\n<h2>\u56db\u3001\u8f97\u8f6c\u76f8\u9664\u6cd5\u4ee3\u7801\u5b9e\u73b0<\/h2>\n<p><strong>\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5 = \u8f97\u8f6c\u76f8\u9664\u6cd5\u6cd5<\/strong>\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=O3RMkMp2W7wR%2FUpWjwRSxQ%3D%3D.eHm4Ngvzeis8h9IwV5YxZODhKTxQuZYGwvWv39vCS1KXgEGvNENTwm7U1DskYj0LGbKNkmZ%2B7Q5tAhi5Uredrg%3D%3D\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki&#8230;<\/a><\/p>\n<p>\u5728\u8f97\u8f6c\u76f8\u9664\u6cd5\u7684\u5b9e\u73b0\u4e2d\uff0c\u8ba1\u7b97\u6700\u5927\u516c\u7ea6\u6570\u7684\u65b9\u5f0f\uff0c\u5c31\u662f\u4f7f\u7528\u4e00\u4e2a\u6570\u5b57\u51cf\u53bb\u53e6\u5916\u4e00\u4e2a\u6570\u5b57\uff0c\u76f4\u5230\u4e24\u4e2a\u6570\u5b57\u76f8\u540c\u6216\u8005\u6709\u5176\u4e2d\u4e00\u4e2a\u6570\u5b57\u4e3a0\uff0c\u90a3\u4e48\u6700\u540e\u4e0d\u4e3a\u96f6\u7684\u90a3\u4e2a\u6570\u5b57\u5c31\u662f\u4e24\u6570\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002<\/p>\n<p>\u5c0f\u5085\u54e5\u5728\u8fd9\u91cc\u63d0\u4f9b\u4e862\u79cd\u8ba1\u7b97\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u5faa\u73af\u53e6\u5916\u4e00\u79cd\u662f\u9012\u5f52\u3002\u2014\u2014 \u65b9\u4fbf\u5f88\u591a\u770b\u4e0d\u61c2\u9012\u5f52\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u7528\u53e6\u5916\u7684\u65b9\u5f0f\u5b66\u4e60\u3002<\/p>\n<h3>1. \u5faa\u73af\u5b9e\u73b0<\/h3>\n<pre><code>public long gcd01(long m, long n) {\n    m = Math.abs(m);\n    n = Math.abs(n);\n    \n    while (m != 0 &amp;&amp; n != 0 &amp;&amp; m != n) {\n        if (m &gt; n) {\n            m = m - n;\n        } else {\n            n = n - m;\n        }\n    }\n    return m == 0 ? n : m;\n}<\/code><\/pre>\n<ul>\n<li>\u4e24\u6570\u5faa\u73af\u5904\u7406\u4e2d\uff0c\u6761\u4ef6\u4e3a <code>m != 0 &amp;&amp; n != 0 &amp;&amp; m != n<\/code> \u76f4\u81f3\u5faa\u73af\u7ed3\u675f\u3002<\/li>\n<\/ul>\n<h3>2. \u9012\u5f52\u5b9e\u73b0<\/h3>\n<pre><code>public long gcd02(long m, long n) {\n    if (m &lt; n) {\n        long k = m;\n        m = n;\n        n = k;\n    }\n    if (m % n != 0) {\n        long temp = m % n;\n        return gcd02(n, temp);\n    } else {\n        return n;\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u8ba1\u7b97\u65b9\u5f0f\u903b\u8f91\u548c\u6761\u4ef6\u662f\u4e00\u6837\u7684\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e2a\u662f\u4f7f\u7528\u4e86\u9012\u5f52\u8c03\u7528\u7684\u65b9\u5f0f\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<\/ul>\n<h3>3. \u6d4b\u8bd5\u9a8c\u8bc1<\/h3>\n<pre><code>@Test\npublic void test_euclidean() {\n    Euclidean euclidean = new Euclidean();\n    System.out.println(euclidean.gcd01(124, 20));\n    System.out.println(euclidean.gcd02(124, 20));\n}<\/code><\/pre>\n<p><strong>\u6d4b\u8bd5\u7ed3\u679c<\/strong><\/p>\n<pre><code>4\n4\n\n\nProcess finished with exit code 0<\/code><\/pre>\n<ul>\n<li>\u8ba1\u7b97 124 \u548c 20 \u7684\u6700\u5927\u516c\u7ea6\u6570\uff0c\u4e24\u4e2a\u8ba1\u7b97\u65b9\u5f0f\u7ed3\u679c\u90fd\u662f 4 \u3002\u597d\u7684\uff0c\u5230\u8fd9\u6d4b\u8bd5\u901a\u8fc7\u3002<\/li>\n<li>\u8fd9\u5e76\u4e0d\u662f\u4e00\u4e2a\u5f88\u96be\u7684\u77e5\u8bc6\u70b9\uff0c\u4f46\u5f53\u4f60\u505a\u4e00\u4e9b\u6280\u672f\u5206\u4eab\u3001\u7b54\u8fa9\u8ff0\u804c\u7b49\u65f6\u5019\uff0c\u80fd\u8fd9\u6837\u7528\u6280\u672f\u8bed\u8a00\u800c\u4e0d\u662f\u5927\u767d\u8bdd\u7684\u8bb2\u8ff0\u51fa\u6765\u540e\uff0c\u5176\u5b9e\u9ad8\u5ea6\u5c31\u6709\u4e86\u3002\u5144\u5f1f\uff01\ud83d\udc6c\ud83c\udffb<\/li>\n<\/ul>\n<hr>\n<p>\u5728 <a href=\"https:\/\/link.segmentfault.com\/?enc=6BReKQ2xwb%2FMoo%2FBE%2F91ng%3D%3D.%2BHANeDzFLqG%2FLJ9yepVEc38S%2FYsHp9TjW5U%2B%2BiBs9vXjkumcK459%2FEclB6haycZNcsRer8iXZSjkR2U9INWfmPPPivqYPu2%2BmTFmkau26gQ4pofQCAaDyRprnbBhpRvVbCPxil9OtNB%2BD8w2X3Pz6IvDkWZj8ryJ%2Bg8tXrD4mJg%3D\" rel=\"nofollow\">stackoverflow.com<\/a> \u770b\u5230\u4e00\u9053\u95ee\u9898\uff1a<strong>\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\u7684\u6700\u6709\u6548\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043300065\" alt=\"img\" title=\"img\" loading=\"lazy\"><\/p>\n<p>\u4e4d\u4e00\u770b\uff0c\ud83e\udd28 \u8fd9\u80fd\u6709\u5565\u3002\u4e0d\u5c31\u662f\u8ba1\u7b97\u4e0b\u6700\u5c0f\u516c\u500d\u6570\u5417\uff1f\u4f46\u4e00\u60f3\u6211\u8111\u888b\u4e2d\u8ba1\u7b97\u6700\u5c0f\u516c\u500d\u6570\u7684\u65b9\u6cd5\uff1b\u4e00\u79cd\u662f\u5728\u672c\u5b50\u4e0a\u901a\u8fc7<a href=\"https:\/\/link.segmentfault.com\/?enc=60IZ1dDP9wU1mK4pD4Ffcg%3D%3D.UK5oiSWQgM7ltfqCHJ4ePNWDF4Fc7ytWQw%2BXVyxGfIJTlzCnTxVUVeCf3Ym4q7mk\" rel=\"nofollow\">\u77ed\u9664\u6cd5<\/a>\u8ba1\u7b97\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u57fa\u4e8e\u8ba1\u7b97\u51fa\u7684\u6700\u5927\u516c\u7ea6\u6570\uff0c\u518d\u4f7f\u7528\u516c\u5f0f\uff1a<code>lcm(a, b) = |a * b| \/ gcd(a, b)<\/code> \u6c42\u5f97\u6700\u5c0f\u516c\u500d\u6570\u3002\u2014\u2014 \u8ba1\u7b97\u6700\u5927\u516c\u7ea6\u6570\u662f\u57fa\u4e8e<a href=\"https:\/\/link.segmentfault.com\/?enc=fC1W%2BH6Vv%2FzcY0JHVLpbyQ%3D%3D.EMDEhazfUFhbXmn%2FWl1E%2BAZfWpLf5s0WaReksvuq6cmbfgbIP1B72eh8EzyA0KzE8dgnL63IDxPC6hmNt6MfJR1GYsRLlBYez8OLJ66pJS8%3D\" rel=\"nofollow\">\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5(\u8f97\u8f6c\u76f8\u9664\u6cd5)<\/a><\/p>\n<p>\u90a3\u4e48\u8fd9\u6837\u7684\u8ba1\u7b97\u65b9\u6cd5\u662f\u4e0d\u662f\u6700\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u53e6\u5916\u5982\u679c\u662f\u540c\u65f6\u8ba1\u7b97\u591a\u4e2a\u6574\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\uff0c\u8981\u600e\u4e48\u5904\u7406\uff1f<\/p>\n<p>\u5176\u5b9e\u7f16\u7a0b\u7684\u5b66\u4e60\u5f80\u5f80\u5c31\u662f\u8fd9\u6837\uff0c\u7559\u5fc3\u5904\u5904\u90fd\u662f\u5b66\u95ee\uff0c\u4f60\u603b\u662f\u9700\u8981\u4ece\u5404\u79cd\u7ec6\u5c0f\u7684\u70b9\u4e2d\uff0c\u79ef\u7d2f\u81ea\u5df1\u7684\u6280\u672f\u601d\u7ef4\u5e7f\u5ea6\u548c\u7eb5\u5411\u63a2\u7d22\u6df1\u5ea6\u3002\u597d\u5566\uff0c\u63a5\u4e0b\u6765\u5c0f\u5085\u54e5\u5c31\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u51e0\u79cd\u7528\u4e8e\u8ba1\u7b97\u6700\u5c0f\u516c\u500d\u6570\u7684\u7b97\u6cd5\u3002<\/p>\n<h2>\u4e94\u3001\u7528\u516c\u7ea6\u6570\u5b9e\u73b0<\/h2>\n<p>\u516c\u5f0f\uff1a<code>lcm(a, b) = |a * b| \/ gcd(a, b)<\/code><\/p>\n<pre><code>public long lcm01(long m, long n) {\n    return ((m == 0) || (n == 0)) ? 0 : Math.abs(m * n) \/ gcd(m, n);\n}\n\nprivate long gcd(long m, long n) {\n    m = Math.abs(m);\n    n = Math.abs(n);\n    \/\/ \u4ece\u4e00\u4e2a\u6570\u5b57\u4e2d\u51cf\u53bb\u53e6\u4e00\u4e2a\u6570\u5b57\uff0c\u76f4\u5230\u4e24\u4e2a\u6570\u5b57\u53d8\u5f97\u76f8\u540c\u3002\n    \/\/ \u8fd9\u5c06\u662f GCD\u3002\u5982\u679c\u5176\u4e2d\u4e00\u4e2a\u6570\u5b57\u4e3a\u96f6\uff0c\u4e5f\u9000\u51fa\u5faa\u73af\u3002\n    \/\/ https:\/\/en.wikipedia.org\/wiki\/Euclidean_algorithm\n    while (m != 0 &amp;&amp; n != 0 &amp;&amp; m != n) {\n        if (m &gt; n) {\n            m = m - n;\n        } else {\n            n = n - m;\n        }\n    }\n    return m == 0 ? n : m;\n}<\/code><\/pre>\n<ul>\n<li>\u9996\u5148\u8fd9\u91cc\u662f\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u57fa\u4e8e\u4e24\u6570\u4e58\u79ef\u9664\u4ee5\u6700\u5927\u516c\u7ea6\u6570\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u5c31\u662f\u6700\u5c0f\u516c\u500d\u6570\u3002<\/li>\n<\/ul>\n<h2>\u516d\u3001\u7b80\u5355\u7d2f\u52a0\u8ba1\u7b97<\/h2>\n<p>\u6b64\u8ba1\u7b97\u65b9\u5f0f\u4e3a\uff0c\u5728\u4e00\u7ec4\u6b63\u6574\u6570\u6570\u5217\u4e2d\uff0c\u901a\u8fc7\u627e\u5230\u6700\u5c0f\u7684\u6570\u5b57\u8fdb\u884c\u81ea\u8eab\u7d2f\u52a0\u5faa\u73af\uff0c\u76f4\u81f3\u6240\u6709\u6570\u5b57\u76f8\u540c\u65f6\uff0c\u5219\u8fd9\u4e2a\u6570\u5b57\u4e3a\u6700\u5c0f\u516c\u500d\u6570\u3002\u2014\u2014 \u4f60\u80fd\u4ee3\u7801\u5b9e\u73b0\u4e00\u4e0b\u5417\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043300066\" alt=\"img\" title=\"img\" loading=\"lazy\"><\/p>\n<pre><code>public long lcm02(long... n) {\n    long[] cache = n.clone();\n    \/\/ \u4ee5\u6240\u6709\u6570\u5b57\u90fd\u76f8\u7b49\u4f5c\u4e3a\u6761\u4ef6\n    while (!isEquals(n)) {\n        System.out.println(JSON.toJSONString(n));\n        long min = n[0];\n        int idx = 0;\n        for (int i = 0; i &lt; n.length; i++) {\n            if (min &gt; n[i]) {\n                min = n[i];\n                idx = i;\n            }\n        }\n        n[idx] = cache[idx] + min;\n    }\n    return n[0];\n}<\/code><\/pre>\n<ul>\n<li>\u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u9996\u5148\u8981\u628an\u4e2a\u6574\u6570\u6570\u5217\u8fdb\u884c\u514b\u9686\u4fdd\u5b58\u3002\u56e0\u4e3a\u6bcf\u6b21\u76f8\u52a0\u7684\u90fd\u662f\u6700\u521d\u7684\u8fd9\u4e2a\u6570\u5217\u91cc\u7684\u6570\u5b57\u503c\u3002\u63a5\u4e0b\u6765\u5c31\u662f\u4ee5\u6240\u6709\u6570\u5b57\u90fd\u76f8\u7b49\u4f5c\u4e3a\u6761\u4ef6\u5faa\u73af\u5224\u65ad\uff0c\u4e0d\u65ad\u5730\u7684\u7d2f\u52a0\u6700\u5c0f\u7684\u6570\u503c\u5373\u53ef\u3002\u6700\u7ec8\u8fd4\u56de\u7684\u5c31\u662f\u6700\u5c0f\u516c\u500d\u6570\u3002<\/li>\n<\/ul>\n<h2>\u4e03\u3001\u8868\u683c\u63a8\u6f14\u8ba1\u7b97<\/h2>\n<p>\u8868\u683c\u8ba1\u7b97\u65b9\u5f0f\u4e3a\u5c06\u4e00\u7ec4\u6570\u5b57\u4ee5\u6700\u5c0f\u7684\u8d28\u65702\u5f00\u59cb\u6574\u9664\uff0c\u76f4\u5230\u4e0d\u80fd\u88ab2\u6574\u9664\u540e\uff0c\u7528\u4e0b\u4e00\u4e2a\u8d28\u65703\u7ee7\u7eed\u6574\u9664\uff08\u5269\u4f59\u7684\u6570\u5b57\u4e2d\u6bd4\u5927\u7684\u6700\u5c0f\u7684\u8d28\u6570\uff09\u76f4\u81f3\u6240\u6709\u6570\u5b57\u90fd\u4e3a1\u7684\u65f6\u5019\u7ed3\u675f\u3002\u6700\u7ec8\u6240\u6709\u6709\u6548\u7684\u8d28\u6570\u4e58\u79ef\u5c31\u662f\u6700\u5c0f\u516c\u500d\u6570\u3002\u2014\u2014 \u60f3\u60f3\u5982\u679c\u8fd9\u8ba9\u4f60\u7528\u4ee3\u7801\u5b9e\u73b0\uff0c\u4f60\u80fd\u809d\u51fa\u6765\u5417\uff1f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043300067\" alt=\"img\" title=\"img\" loading=\"lazy\"><\/p>\n<pre><code>public long lcm03(long... n) {\n    Map&lt;Long, List&lt;Long&gt;&gt; keys = new HashMap&lt;&gt;();\n    for (long key : n) {\n        keys.put(key, new ArrayList&lt;Long&gt;() {{\n            add(key);\n        }});\n    }\n    System.out.print(&quot;\u6267\u884c\u8868\u683c\u8ba1\u7b97\uff1a\/r\/nx &quot;);\n    long primality = 2, cachePrimality = primality, filterCount = 0, lcm = 1;\n    \/\/ \u4ee5\u6240\u6709\u5143\u7d20\u6700\u540e\u4e00\u4f4d\u4e3a1\u4f5c\u4e3a\u6761\u4ef6\n    while (filterCount != keys.size()) {\n        int refresh = 0;\n        filterCount = 0;\n        for (Map.Entry&lt;Long, List&lt;Long&gt;&gt; entry : keys.entrySet()) {\n            long value = entry.getValue().get(entry.getValue().size() - 1);\n            if (value == 1) {\n                filterCount++;\n            }\n            \/\/ \u6574\u9664\u5904\u7406\n            if (value % primality == 0) {\n                entry.getValue().add(value \/ primality);\n                refresh++;\n            } else {\n                entry.getValue().add(value);\n            }\n        }\n        \/\/ \u5237\u65b0\u9664\u6570\n        if (refresh == 0) {\n            for (Map.Entry&lt;Long, List&lt;Long&gt;&gt; entry : keys.entrySet()) {\n                long value = entry.getValue().get(entry.getValue().size() - 1);\n                \/\/ \u627e\u5230\u4e0b\u4e00\u4e2a\u7b26\u5408\u7684\u7d20\u6570\n                if (value &gt; primality || (value &lt; cachePrimality &amp;&amp; value &gt; primality)) {\n                    cachePrimality = value;\n                }\n                entry.getValue().remove(entry.getValue().size() - 1);\n            }\n            primality = cachePrimality;\n        } else {\n            \/\/ \u7d2f\u8ba1\u4e58\u79ef\n            lcm *= cachePrimality;\n            System.out.print(cachePrimality + &quot; &quot;);\n        }\n    }\n    keys.forEach((key, values) -&gt; {\n        System.out.println();\n        for (long v : values) {\n            System.out.print(v + &quot; &quot;);\n        }\n    });\n    System.out.println(&quot;\/r\/n&quot;);\n    return lcm;\n}<\/code><\/pre>\n<ul>\n<li>\u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\u6211\u4eec\u901a\u8fc7 Map \u4f5c\u4e3a\u8868\u7684key\uff0cMap \u4e2d\u7684 List \u4f5c\u4e3a\u8868\u6bcf\u4e00\u884c\u6570\u636e\u3002\u901a\u8fc7\u8fd9\u6837\u4e00\u4e2a\u7ed3\u6784\u6784\u5efa\u51fa\u4e00\u5f20\u8868\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\u4ee5\u6240\u6709\u5143\u7d20\u6700\u540e\u4e00\u4f4d\u4e3a1\u4f5c\u4e3a\u6761\u4ef6\u5faa\u73af\u5904\u7406\u6570\u636e\uff0c\u7528\u6700\u5f00\u59cb\u76842\u4f5c\u4e3a\u7d20\u6570\u6574\u9664\u5217\u8868\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u4fdd\u5b58\u5230\u4e0b\u4e00\u7ec4\u6570\u5217\u4e2d\u3002\u5f532\u4e0d\u80fd\u6574\u9664\u65f6\uff0c\u5219\u5237\u65b0\u7d20\u6570\uff0c\u9009\u53d6\u53e6\u5916\u4e00\u4e2a\u5217\u8868\u4e2d\u6700\u5c0f\u7684\u7d20\u6570\u4f5c\u4e3a\u9664\u6570\u7ee7\u7eed\u3002<\/li>\n<li>\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u4f1a\u7d2f\u8ba1\u6709\u6548\u7d20\u6570\u7684\u4e58\u79ef\uff0c\u8fd9\u4e2a\u4e58\u79ef\u7684\u6700\u7ec8\u7ed3\u679c\u5c31\u662f\u6700\u5c0f\u516c\u500d\u6570\u3002<\/li>\n<\/ul>\n<h2>\u516b\u3001\u6d4b\u8bd5\u9a8c\u8bc1<\/h2>\n<p><strong>\u5355\u5143\u6d4b\u8bd5<\/strong><\/p>\n<pre><code>@Test\npublic void test_euclidean() {\n    LastCommonMultiple lastCommonMultiple = new LastCommonMultiple();\n    \/\/ System.out.println(&quot;\u6700\u5c0f\u516c\u500d\u6570\uff1a&quot; + lastCommonMultiple.lcm01(2, 7));\n    System.out.println(&quot;\u6700\u5c0f\u516c\u500d\u6570\uff1a&quot; + lastCommonMultiple.lcm02(3, 4, 6));\n    \/\/ System.out.println(&quot;\u6700\u5c0f\u516c\u500d\u6570\uff1a&quot; + lastCommonMultiple.lcm03(3, 4, 6));\n     System.out.println(&quot;\u6700\u5c0f\u516c\u500d\u6570\uff1a&quot; + lastCommonMultiple.lcm03(3, 4, 6, 8));\n   \/\/System.out.println(&quot;\u6700\u5c0f\u516c\u500d\u6570\uff1a&quot; + lastCommonMultiple.lcm03(4, 7, 12, 21, 42));\n}<\/code><\/pre>\n<p><strong>\u6d4b\u8bd5\u7ed3\u679c<\/strong><\/p>\n<pre><code>\u6267\u884c\u7d2f\u52a0\u8ba1\u7b97\uff1a\n[3,4,6]\n[6,4,6]\n[6,8,6]\n[9,8,6]\n[9,8,12]\n[9,12,12]\n\u6700\u5c0f\u516c\u500d\u6570\uff1a12\n\n\u6267\u884c\u8868\u683c\u8ba1\u7b97\uff1a\nx 2 2 2 3 \n3 3 3 3 1 \n4 2 1 1 1 \n6 3 3 3 1 \n8 4 2 1 1 \n\n\u6700\u5c0f\u516c\u500d\u6570\uff1a24<\/code><\/pre>\n<ul>\n<li>\u5230\u8fd9\u91cc\u6d4b\u8bd5\u5c31\u7ed3\u675f\u4e86\uff0c\u672c\u7ae0\u4e00\u5171\u4ecb\u7ecd\u4e86\u4e09\u79cd\u8ba1\u7b97\u6700\u5c0f\u516c\u500d\u6570\u7684\u65b9\u6cd5\u3002\u90a3\u5982\u679c\u53ea\u8ba9\u4f60\u770b\u5230\u903b\u8f91\uff0c\u4f60\u80fd\u5199\u51fa\u6700\u7ec8\u7684\u4ee3\u7801\u5417\uff1f<\/li>\n<\/ul>\n<h2>\u4e5d\u3001\u5e38\u89c1\u9762\u8bd5<\/h2>\n<ul>\n<li>\u6700\u5927\u516c\u7ea6\u6570\u7684\u4f7f\u7528\u7528\u9014\uff1f<\/li>\n<li>\u5982\u4f55\u4f7f\u7528\u4ee3\u7801\u5b9e\u73b0\u6700\u5927\u516c\u7ea6\u6570\u8ba1\u7b97\uff1f<\/li>\n<li>\u4f60\u662f\u5426\u4e86\u89e3\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5\uff1f<\/li>\n<li>\u5173\u4e8e\u6570\u8bba\u4f60\u8fd8\u8bb0\u5f97\u591a\u5c11\uff1f<\/li>\n<li>RSA \u52a0\u5bc6\u7b97\u6cd5\u4e3a\u4ec0\u4e48\u9700\u8981\u7528\u5230\u516c\u7ea6\u6570\u8ba1\u7b97\uff1f<\/li>\n<li>\u5982\u4f55\u8ba1\u7b97\u4e24\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\uff1f<\/li>\n<li>\u5982\u679c\u8ba1\u7b97\u591a\u4e2a\u6574\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\uff1f<\/li>\n<li>\u4f60\u80fd\u8bf4\u4e00\u4e0b\u5177\u4f53\u5982\u4f55\u5b9e\u73b0\u8fd9\u79cdX\u7684\u8ba1\u7b97\u6d41\u7a0b\u5417\uff1f<\/li>\n<li>\u4f60\u77e5\u9053\u6700\u5c0f\u516c\u500d\u6570\u8ba1\u7b97\u7684\u7528\u9014\u5417\uff1f<\/li>\n<\/ul>\n<hr>\n<ul>\n<li>What is the most efficient way to calculate the least common multiple of two integers?\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=RLNYWn5KAFrL1JRzGHCrbw%3D%3D.ywh4t8q1ZlTSHEvXfEMjlTCHeKNtwA4AZezrTjQ3m566zFByBQExlNQVVjaoMO2A7fPickVis%2BYG55X3J5FEbThXG3%2BnxdR9bKZLG1iutQfXrXzSe1dVMFrrwdA93CbChR4ucnBAo4HXrB4HuG20z%2B4u7SPX4sX3BaSJ%2BfbQAwK76K70sbsuNwzejPdIyaZK\" rel=\"nofollow\">https:\/\/stackoverflow.com\/que&#8230;<\/a><\/li>\n<li>Least common multiple\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=EnogeccM%2B32zu%2F3X%2Bd8vGQ%3D%3D.leICyXATUFO8fmkUs%2FLcy7ub2AzYWBRWhkL7VM76GA8IsUnp%2BoFK%2BcOgSW9yMc4J5NJ34eCFidfV29BvKuUe0Q%3D%3D\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki&#8230;<\/a><\/li>\n<li>Chebyshev function\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=GaQW62Qrwi3ll5wsqsBOPw%3D%3D.EX3iwqQyKRMOQIMPiV%2FXwUVCc5GkzpmlNG82tR33LWUaIdnaShEucdQYKMA%2B7Yx%2FFdcaEVew9ZSwPLOtz7%2Fs%2BA%3D%3D\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki&#8230;<\/a><\/li>\n<li>\u6b27\u51e0\u91cc\u5fb7\u7b97\u6cd5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=MzCAYBuMJjgnpT4mLIGCDQ%3D%3D.%2BRdH%2Fc6l8CdD7tQs5rKNYHF3VP40o0wb3fQWbuQ8Six%2FvS5lqMPUi%2BGsaqZfd5Pd%2Ft9hzch3fhpDyy7ov7F5Dg%3D%3D\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki&#8230;<\/a><\/li>\n<li>\u7ebf\u6027\u7ec4\u5408\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=llwegC%2Fhpyth5bDT26GH1g%3D%3D.HBpflU1mdry2U1yOMkY7Ioq3rl5lu%2BDxiUfTkvkv%2BkWb9Iig6WIaivj%2FleAwE7%2BZLPfB6H4KopP%2FF6vX9mjgTg%3D%3D\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki&#8230;<\/a><\/li>\n<li>\u8d1d\u7956\u5b9a\u7406\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=JlUEgEz%2Bl3PXpJRMnIl7EQ%3D%3D.q24D8mGSeB8bLD2RYpyB6dydz8JDQtVWYxa78zza9cPxtGFSmM4pEdtSgtTPT%2FTK\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki\/B%C3%A9zout%27s_identity<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043300055\">https:\/\/segmentfault.com\/a\/1190000043300055<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u5c0f\u5085\u54e5\u535a\u5ba2\uff1ahttps:\/\/bugstack.cn\u6e90\u7801\uff1ahttps:\/\/github.com\/fuzhe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10007067","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10007067"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007067\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10007067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10007067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10007067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}