{"id":303,"date":"2019-09-28T22:25:01","date_gmt":"2019-09-28T14:25:01","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=303"},"modified":"2019-09-28T22:25:01","modified_gmt":"2019-09-28T14:25:01","slug":"vijos-1047-%e6%9c%80%e5%b0%8f%e5%85%ac%e5%80%8d%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=303","title":{"rendered":"Vijos 1047 \u2014 \u6700\u5c0f\u516c\u500d\u6570"},"content":{"rendered":"<h3>\u63cf\u8ff0<\/h3>\n<p>\u7ed9\u51fa\u4e24\u4e2a\u6b63\u6574\u6570a,b(1&lt;=a,b&lt;=10^100)\uff0c\u6c42\u8fd9\u4e24\u4e2a\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\u3002<\/p>\n<h3>\u9898\u76ee\u94fe\u63a5<\/h3>\n<p><a href=\"https:\/\/vijos.org\/p\/1047\" title=\"https:\/\/vijos.org\/p\/1047\">https:\/\/vijos.org\/p\/1047<\/a><\/p>\n<h3>\u8f93\u5165\u683c\u5f0f<\/h3>\n<p>\u4ec5\u4e00\u884c\uff0c\u5305\u542b\u4e24\u4e2a\u6b63\u6574\u6570a\u548cb, \u4e2d\u95f4\u4ee5\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00<\/p>\n<h3>\u8f93\u51fa\u683c\u5f0f<\/h3>\n<p>\u4ec5\u5305\u542b\u4e00\u884c\uff0c\u4e3aa\u548cb\u7684\u6700\u5c0f\u516c\u500d\u6570lcm(a,b)<\/p>\n<h3>\u6837\u4f8b\u8f93\u5165<\/h3>\n<p><code>123 321<\/code><\/p>\n<h3>\u6837\u4f8b\u8f93\u51fa<\/h3>\n<p><code>13161<\/code><\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u5148\u4f7f\u7528\u8f97\u8f6c\u76f8\u9664\u6cd5\u6c42\u6700\u5927\u516c\u7ea6\u6570 gcd(a,b)\uff0c\u7136\u540e <code>a * b \/ gcd(a, b)<\/code> \u5c31\u662f\u6700\u5c0f\u516c\u500d\u6570\u3002\u56e0\u4e3a\u4e24\u4e2a\u6570\u7684\u4e58\u79ef\u7b49\u4e8e\u5b83\u4eec\u7684\u6700\u5927\u516c\u7ea6\u6570(gcd)\u4e0e\u6700\u5c0f\u516c\u500d\u6570(lcm)\u4e4b\u79ef\uff0c\u5373 <code>a * b = gcd(a, b) * lcm(a, b)<\/code><br \/>\n<strong>C++\uff1a<\/strong><br \/>\n\u8fd9\u9053\u9898\u7684\u6570\u636e\u8303\u56f4\u5f88\u5927\uff0c\u5373\u4f7f\u7528 long long \u4e5f\u4e0d\u884c\u3002\u6240\u4ee5\u5e94\u8be5\u7528\u5b57\u7b26\u4e32\u5b58\u50a8\u6570\u5b57\uff0c\u6839\u636e\u6570\u5b66\u4e2d\u7684\u52a0\u51cf\u4e58\u9664\u7684\u8ba1\u7b97\u65b9\u6cd5\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u7684\u529f\u80fd\u3002<br \/>\n<strong>Java\uff1a<\/strong><br \/>\nJava\u4e2d\u6709 BigInteger \u7c7b\uff0c\u53ef\u4ee5\u8fdb\u884c\u5927\u6570\u8fd0\u7b97\u3002<br \/>\n<strong>Python\uff1a<\/strong><br \/>\n\u76f4\u63a5\u8fd0\u7b97\u5c31\u884c\u4e86\u3002\u4f46\u8981\u6ce8\u610f\u8f93\u51fa\u7684\u65f6\u5019\u4e0d\u8981\u5e26\u5c0f\u6570\u70b9\u3002<\/p>\n<p>\u4f46\u662f\u6211\u8981\u8bf4\u4e00\u53e5\uff0c\u8fd9\u5e76\u4e0d\u4ee3\u8868 C++ \u5f88\u5783\u573e\uff0c\u5728\u7b97\u6cd5\u6bd4\u8d5b\u4e2d\u4f7f\u7528 C++ \u4ecd\u662f\u6bd4\u8f83\u597d\u7684\u9009\u62e9\u3002\u5f53\u7136\uff0c\u591a\u5b66\u4e60\u51e0\u95e8\u8bed\u8a00\uff0c\u6839\u636e\u5177\u4f53\u7684\u9898\u76ee\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u8bed\u8a00\u66f4\u597d\u3002<\/p>\n<h3>AC\u4ee3\u7801\uff08C++\uff09<\/h3>\n<p>\u6211\u592a\u61d2\u4e86\uff0c\u4ee5\u540e\u6709\u7a7a\u518d\u5199\u3002<\/p>\n<h3>AC\u4ee3\u7801\uff08Java\uff09<\/h3>\n<pre><code class=\"language-Java line-numbers\">import java.util.*;\nimport java.math.*;\n\npublic class Main {\n    public static BigInteger gcd(BigInteger a, BigInteger b) {\n        if (b.compareTo(new BigInteger(\"0\")) == 0) {\n            return a;\n        }\n        return gcd(b, a.mod(b));\n    }\n\n    public static void main(String[] args) {\n        Scanner in = new Scanner(System.in);\n        BigInteger a = in.nextBigInteger(), b = in.nextBigInteger();\n        System.out.println(a.multiply(b).divide(gcd(a, b)));\n    }\n}\n<\/code><\/pre>\n<h3>AC\u4ee3\u7801\uff08Python\uff09<\/h3>\n<pre><code class=\"language-Python line-numbers\">import math\n\na, b = map(int, input().split())\nprint(a * b \/\/ math.gcd(a, b))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u63cf\u8ff0 \u7ed9\u51fa\u4e24\u4e2a\u6b63\u6574\u6570a,b(1&lt;=a,b&lt;=10^100)\uff0c\u6c42\u8fd9\u4e24\u4e2a\u6570\u7684\u6700\u5c0f\u516c\u500d\u6570\u3002 \u9898\u76ee\u94fe\u63a5 h [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[16,26,29,67],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-algo","tag-java","tag-python","tag-vijos","tag-67"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}