{"id":3486,"date":"2017-12-25T15:07:46","date_gmt":"2017-12-25T12:07:46","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=3486"},"modified":"2017-12-26T12:24:20","modified_gmt":"2017-12-26T09:24:20","slug":"e-olymp-1560-%d1%83%d0%bc%d0%b5%d0%bd%d1%8c%d1%88%d0%b0%d1%8e%d1%89%d0%b5%d0%b5%d1%81%d1%8f-%d1%87%d0%b8%d1%81%d0%bb%d0%be","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=3486","title":{"rendered":"e-olymp 1560. \u0423\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u0447\u0438\u0441\u043b\u043e"},"content":{"rendered":"<h2>\u0417\u0430\u0434\u0430\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0430\u0434 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <strong>3<\/strong>, \u0442\u043e \u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 <strong>3<\/strong>;<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <strong>2<\/strong>, \u0442\u043e \u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 <strong>2<\/strong>;<\/li>\n<li>\u0412\u044b\u0447\u0438\u0442\u0430\u0442\u044c <strong>1<\/strong>.<\/li>\n<\/ol>\n<p>\u041f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 [latex]n[\/latex]\u00a0\u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f <strong>1<\/strong>.<\/p>\n<h2>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e [latex]\u00a0n(1 \u2264 n \u2264 10^{6})[\/latex].<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f [latex]n[\/latex] \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f <strong>1<\/strong>.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u044b<\/h2>\n<table style=\"width: 362.875px\">\n<tbody>\n<tr>\n<td style=\"width: 150px\">\u0412\u0432\u043e\u0434<\/td>\n<td style=\"width: 201.875px\">\u0412\u044b\u0432\u043e\u0434<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 150px\">1<br \/>\n5<br \/>\n10<\/td>\n<td style=\"width: 201.875px\">0<br \/>\n3<br \/>\n3<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 150px\">12<br \/>\n7<br \/>\n21<\/td>\n<td style=\"width: 201.875px\">3<br \/>\n3<br \/>\n4<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 150px\">256<br \/>\n1037<br \/>\n8771<br \/>\n9022<br \/>\n102651<\/td>\n<td style=\"width: 201.875px\">8<br \/>\n11<br \/>\n13<br \/>\n13<br \/>\n19<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u041a\u043e\u0434<\/h2>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\npublic class Main\r\n{\r\n\tint[] x = new int[1000001];\r\n\t\r\n\tpublic int operations(int n)\r\n\t{\r\n\t\tx[1] = 0;\r\n\t\tfor (int i = 2; i &lt;= n; i++)\r\n\t\t{\r\n\t\t\tx[i] = x[i-1] + 1;\r\n\t\t\tif (i%2 == 0)\r\n\t\t\t{\r\n\t\t\t\tx[i] = Math.min(x[i], x[i\/2] + 1);\r\n\t\t\t}\r\n\t\t\tif (i%3 == 0)\r\n\t\t\t{\r\n\t\t\t\tx[i] = Math.min(x[i], x[i\/3] + 1);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn x[n];\r\n\t}\r\n\r\n\t\r\n\tpublic static void main (String[] args)\r\n\t{\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tMain x = new Main();\r\n\t\twhile (in.hasNextInt())\r\n\t\t{\r\n\t\t\tint n = in.nextInt();\r\n\t\t\tSystem.out.println(x.operations(n));\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0417\u0430\u0432\u0435\u0434\u0451\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. x[1] \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d 0, \u0442\u0430\u043a \u043a\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u043a \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u043d\u0443\u0436\u043d\u043e 0 \u0448\u0430\u0433\u043e\u0432. \u0417\u0430\u0442\u0435\u043c, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043f\u0440\u043e\u0431\u0435\u0436\u0438\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0434\u043e [latex]n[\/latex], \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u043a \u043d\u0438\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0438\u0437 \u0441\u0430\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0434\u0435\u043b\u0435\u043d\u0438\u044f(\u043d\u0430 2 \u0438\u043b\u0438 \u043d\u0430 3) \u0441 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u044b.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>1.<a href=\"https:\/\/ideone.com\/v1VvZX\" target=\"_blank\" rel=\"noopener\">\u041a\u043e\u0434 \u043d\u0430 Ideone<\/a><br \/>\n2.<a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/1560\" target=\"_blank\" rel=\"noopener\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0430 e-olymp<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u043d\u0438\u0435 \u041d\u0430\u0434 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438: \u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 3, \u0442\u043e \u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 3; \u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 2, \u0442\u043e \u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 2; \u0412\u044b\u0447\u0438\u0442\u0430\u0442\u044c 1. \u041f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 [latex]n[\/latex]\u00a0\u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f 1. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e [latex]\u00a0n(1 \u2264 n \u2264 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=3486\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":107,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[348,111],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3486"}],"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\/107"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3486"}],"version-history":[{"count":4,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3486\/revisions"}],"predecessor-version":[{"id":3529,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3486\/revisions\/3529"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}