{"id":3691,"date":"2018-10-02T19:26:21","date_gmt":"2018-10-02T16:26:21","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=3691"},"modified":"2018-11-19T21:32:09","modified_gmt":"2018-11-19T18:32:09","slug":"e-olymp-27-%d1%86%d0%b8%d0%ba%d0%bb%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%b8%d0%b5-%d1%81%d0%b4%d0%b2%d0%b8%d0%b3%d0%b8","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=3691","title":{"rendered":"e-olymp 27. \u0426\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0434\u0432\u0438\u0433\u0438"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<div id=\"attachment_3703\" style=\"width: 285px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3703\" class=\"wp-image-3703 size-full\" src=\"http:\/\/java.mazurok.com\/wp-content\/uploads\/1256126183.gif\" alt=\"\" width=\"275\" height=\"200\" \/><p id=\"caption-attachment-3703\" class=\"wp-caption-text\">\u0426\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0434\u0432\u0438\u0433<\/p><\/div>\n<p>\u0417\u0430\u043f\u0438\u0448\u0435\u043c \u0446\u0435\u043b\u043e\u0435 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $n$\u00a0\u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u043b\u0435\u0432\u044b\u0435 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0434\u0432\u0438\u0433\u0438 \u0447\u0438\u0441\u043b\u0430 $n$, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0435\u0440\u0432\u0430\u044f \u0446\u0438\u0444\u0440\u0430 \u0447\u0438\u0441\u043b\u0430 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0435\u0446.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 $n = 11$, \u0442\u043e \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u044d\u0442\u043e $1011_2$, \u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0434\u0432\u0438\u0433\u0438: $0111_2$, $1110_2$, $1101_2$, $1011_2$. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 $m$\u00a0\u0443 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0447\u0438\u0441\u0435\u043b \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0447\u0438\u0441\u043b\u043e $1110_2 = 14_{10}$.<\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 $n$\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 $m$.<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong>\u00a0\u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e $n (1 \u2264 n \u2264 2\\cdot 10^9)$.<\/p>\n<p><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435<\/strong>\u00a0<strong>\u0434\u0430\u043d\u043d\u044b\u0435:<\/strong>\u00a0\u0438\u0441\u043a\u043e\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $m$.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table style=\"border-collapse: collapse;width: 99.8498%;height: 132px\" border=\"1\">\n<tbody>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\"><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<td style=\"width: 50%;height: 22px\"><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<\/tr>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\">11<\/td>\n<td style=\"width: 50%;height: 22px\">14<\/td>\n<\/tr>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\">23<\/td>\n<td style=\"width: 50%;height: 22px\">30<\/td>\n<\/tr>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\">256<\/td>\n<td style=\"width: 50%;height: 22px\">256<\/td>\n<\/tr>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\">257<\/td>\n<td style=\"width: 50%;height: 22px\">384<\/td>\n<\/tr>\n<tr style=\"height: 22px\">\n<td style=\"width: 49.8498%;height: 22px\">34132<\/td>\n<td style=\"width: 50%;height: 22px\">43664<\/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 \" title=\"e-olymp 27 C++ solution\">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\r\n\t\tlong in_val = in.nextInt(), tmp_val = in_val, power = 1;\r\n\t\twhile (tmp_val != 0) {\r\n\t\t\ttmp_val \/= 2;\r\n\t\t\tpower *= 2;\r\n\t\t}\r\n\t\ttmp_val = in_val;\r\n\t\tlong max_val = in_val;\r\n\t\tdo{\r\n\t\t\tin_val = in_val &lt;&lt; 1;\r\n\t\t\tin_val = in_val % power + (in_val &gt;= power ? 1 : 0);\r\n\t\t\tif (max_val &lt; in_val) max_val = in_val;\r\n\t\t}while (tmp_val != in_val);\r\n\t\tSystem.out.println(max_val);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h1>\n<ol>\n<li>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438, \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430;<\/li>\n<li>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432\u043b\u0435\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0430 \u043e\u0434\u0438\u043d \u0431\u0438\u0442 \u0438 \u0438\u0437 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435.<\/li>\n<\/ol>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u00a0<a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/27\">e-olymp.com<\/a><br \/>\n\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u00a0<a href=\"https:\/\/ideone.com\/GpVEo8\">ideone.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0417\u0430\u043f\u0438\u0448\u0435\u043c \u0446\u0435\u043b\u043e\u0435 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $n$\u00a0\u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u043b\u0435\u0432\u044b\u0435 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0434\u0432\u0438\u0433\u0438 \u0447\u0438\u0441\u043b\u0430 $n$, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0435\u0440\u0432\u0430\u044f \u0446\u0438\u0444\u0440\u0430 \u0447\u0438\u0441\u043b\u0430 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0435\u0446. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 $n = 11$, \u0442\u043e \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u044d\u0442\u043e $1011_2$, \u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0434\u0432\u0438\u0433\u0438: $0111_2$, $1110_2$, $1101_2$, $1011_2$. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 $m$\u00a0\u0443 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0447\u0438\u0441\u0435\u043b \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0447\u0438\u0441\u043b\u043e $1110_2 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=3691\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":121,"featured_media":3703,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[43,398,397],"jetpack_featured_media_url":"https:\/\/java.mazurok.com\/wp-content\/uploads\/1256126183.gif","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3691"}],"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\/121"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3691"}],"version-history":[{"count":13,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3691\/revisions"}],"predecessor-version":[{"id":3705,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3691\/revisions\/3705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/media\/3703"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}