{"id":4022,"date":"2018-12-25T18:31:59","date_gmt":"2018-12-25T15:31:59","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4022"},"modified":"2018-12-25T21:13:57","modified_gmt":"2018-12-25T18:13:57","slug":"e-olymp-2214-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d1%8f-9","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4022","title":{"rendered":"e-olymp 2214. \u0424\u0443\u043d\u043a\u0446\u0438\u044f 9"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0414\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u2014 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430<br \/>\n$$f(M, N)=\\begin{cases}<br \/>\nf(M-N, N), &amp; \\text{ npu } M&gt;N \\\\<br \/>\nN, &amp; \\text{ npu } M=N \\\\<br \/>\nf(N-M, M), &amp; \\text{ npu } N&gt;M<br \/>\n\\end{cases}$$<br \/>\n\u0421\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c (\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443), \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<h2>\u0412\u0432\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0414\u0432\u0430 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 $n$ \u0438 $m$ $(1\\leq n, m \\leq 10^{18}).$<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0418\u0441\u043a\u043e\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u044b<\/h2>\n<table>\n<tr>\n<td>\n\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n<\/td>\n<td>\n\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n<\/td>\n<\/tr>\n<tr>\n<td>\n$6$ $3$\n<\/td>\n<td>\n$3$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$12$ $12$\n<\/td>\n<td>\n$12$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$126$ $98$\n<\/td>\n<td>\n$98$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$10329$ $1501$\n<\/td>\n<td>\n$1501$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$1008359$ $15113$\n<\/td>\n<td>\n$15113$\n<\/td>\n<\/tr>\n<\/table>\n<h2>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h2>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\n\r\nclass Main\r\n{\r\n\tpublic static void main (String[] args) {\r\n\t\tScanner in = new Scanner(System.in);\r\n    \t        long n, m;\r\n    \t        n = in.nextLong();\r\n    \t        m = in.nextLong();\r\n    \t        System.out.print(f(n, m));\r\n\t}\r\n\tstatic long f(long n, long m) {\r\n\t\tif (n % m == 0) return m;\r\n\t        if (m % n == 0) return n;\r\n\t        if (m &gt; n) return f(m % n, n);\r\n\t        else return f(n % m , m);\r\n\t}\r\n}<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>f<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0418\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u043d\u0435 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u0442\u043e \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 $n$ \u0438\u043b\u0438 $m$). \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e (\u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e $n \\mod m = 0$ \u0438\u043b\u0438 $m \\mod n = 0,$ \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  \u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435). \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/2214\">e-olymp<\/a><br \/>\n\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 <a href=\"https:\/\/ideone.com\/7pZJjc\">ideone.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0414\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u2014 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 $$f(M, N)=\\begin{cases} f(M-N, N), &amp; \\text{ npu } M&gt;N \\\\ N, &amp; \\text{ npu } M=N \\\\ f(N-M, M), &amp; \\text{ npu } N&gt;M \\end{cases}$$ \u0421\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c (\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443), \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0412\u0432\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0414\u0432\u0430 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 $n$ \u0438 $m$ $(1\\leq n, m \\leq 10^{18}).$ \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4022\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":132,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[10,565,594,71],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4022"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/132"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4022"}],"version-history":[{"count":8,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4022\/revisions"}],"predecessor-version":[{"id":4430,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4022\/revisions\/4430"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}