{"id":5312,"date":"2020-11-27T20:32:24","date_gmt":"2020-11-27T17:32:24","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=5312"},"modified":"2020-12-01T12:12:34","modified_gmt":"2020-12-01T09:12:34","slug":"e-olymp-8538-%d0%ba%d0%b0%d0%bb%d1%8c%d0%ba%d1%83%d0%bb%d1%8f%d1%82%d0%be%d1%80","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=5312","title":{"rendered":"e-olymp 8538. \u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440"},"content":{"rendered":"<h1>\u0423\u0441\u043b\u043e\u0432\u0438\u0435<\/h1>\n<p>\u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0418\u043b\u044c\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0432\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0430 \u0442\u0440\u0438 \u0438 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u043d\u0435\u043c\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u041d\u0430 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0447\u0438\u0441\u043b\u043e $1$. \u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u0418\u043b\u044c\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0447\u0438\u0441\u043b\u043e $n$.<\/p>\n<h3>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u041e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e $n$ $\\left(10\\leq n\\leq 10^9\\right)$.<\/p>\n<h3>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \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.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table style=\"height: 286px\" width=\"557\">\n<tbody>\n<tr>\n<td>\u2116<\/td>\n<td>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>1447<\/td>\n<td>16<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>18<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>111<\/td>\n<td>6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h1>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Main\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tScanner in = new Scanner (System.in);\r\n\t\tint n = in.nextInt();\r\n\t\tint k = 0;\r\n\t\twhile(n &gt; 0) {\r\n\t\t\tk += n%3 + 1;\r\n\t\t\tn \/= 3;\r\n\t\t}\r\n\t\tSystem.out.print(k - 2);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0420\u0435\u0448\u0438\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e. \u041f\u0443\u0441\u0442\u044c \u043d\u0430\u043c \u0434\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e $n$ \u0438 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0438\u0437 \u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c $1$, \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0432 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0446\u0438\u043a\u043b <code>while()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0430\u0448\u0435 \u0447\u0438\u0441\u043b\u043e $n$ \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 $0$. \u0412\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u0443\u0441\u0442\u044c <code>k<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u043e\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0439 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0438 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f $0$. \u0422\u043e\u0433\u0434\u0430, \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0446\u0438\u043a\u043b\u0430 \u043c\u044b \u043a \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 $3$. <code>n%3<\/code> &#8212; \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u044f\u0442\u044c $1$ \u043e\u0442 $n$ \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0446\u0435\u043b\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 $3$. \u0414\u0430\u043b\u0435\u0435, \u0434\u0435\u043b\u0438\u043c $n$ \u043d\u0430 $3$ \u0438 \u044d\u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044f (\u0447\u0442\u043e \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 $13$). \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0446\u0438\u043a\u043b\u0430 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438, \u0447\u0442\u043e $n &gt; 0$, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0439\u0434\u0451\u043c \u043b\u0438\u0448\u043d\u044e\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u0438 \u043a \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u0438\u0431\u0430\u0432\u044f\u0442\u0441\u044f \u0434\u0432\u0430 \u043b\u0438\u0448\u043d\u0438\u0445 \u0448\u0430\u0433\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435 \u043e\u0442\u0432\u0435\u0442\u0430, \u043e\u0442 $k$ \u043e\u0442\u043d\u0438\u043c\u0430\u0435\u043c $2$.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.e-olymp.com\/uk\/problems\/8538\" target=\"_blank\" rel=\"noopener noreferrer\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 (e-olymp)<\/a><\/li>\n<li><a href=\"https:\/\/ideone.com\/B946vc\" target=\"_blank\" rel=\"noopener noreferrer\">\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f (Ideone)<\/a><\/li>\n<li><a href=\"https:\/\/www.e-olymp.com\/uk\/submissions\/7862761\" target=\"_blank\" rel=\"noopener noreferrer\">\u0417\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0418\u043b\u044c\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0432\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0430 \u0442\u0440\u0438 \u0438 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u043d\u0435\u043c\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u041d\u0430 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0447\u0438\u0441\u043b\u043e $1$. \u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u0418\u043b\u044c\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0447\u0438\u0441\u043b\u043e $n$. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u041e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e $n$ $\\left(10\\leq n\\leq 10^9\\right)$. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \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. \u0422\u0435\u0441\u0442\u044b \u2116 \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 1 1447 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=5312\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":138,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6],"tags":[647,742,743,69,686],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5312"}],"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\/138"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5312"}],"version-history":[{"count":3,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5312\/revisions"}],"predecessor-version":[{"id":5315,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5312\/revisions\/5315"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}