{"id":4868,"date":"2019-02-19T20:21:59","date_gmt":"2019-02-19T17:21:59","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4868"},"modified":"2019-04-11T00:32:47","modified_gmt":"2019-04-10T21:32:47","slug":"e-olymp-419-%d0%b7%d0%b0%d0%b4%d0%b0%d1%87%d0%b0-3n-1","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4868","title":{"rendered":"e-olymp 419. \u0417\u0430\u0434\u0430\u0447\u0430 3n + 1"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<pre class=\"lang:vb decode:true \">input n\r\nprint n\r\nif n = 1 then STOP\r\nif n is odd then n = 3 * n + 1\r\nelse n = n \/ 2\r\nGOTO 2<\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f [latex]n = 22[\/latex] \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u0435\u043b:<\/p>\n<p style=\"text-align: center\"><strong>22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1<\/strong><\/p>\n<p>\u041f\u043e\u043b\u0430\u0433\u0430\u044e\u0442 (\u043d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u043a\u0430\u0437\u0430\u043d\u043e), \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u043a [latex]n = 1[\/latex] \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0433\u043e [latex]n[\/latex]. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0446\u0435\u043b\u044b\u0445 [latex]n[\/latex], \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 [latex]0 &lt; n &lt; 1,000,000[\/latex].<br \/>\n\u0414\u043b\u0438\u043d\u043e\u0439 \u0446\u0438\u043a\u043b\u0430 \u0447\u0438\u0441\u043b\u0430 [latex]n[\/latex] \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u044f [latex]1[\/latex]. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u0438\u043d\u0430 \u0446\u0438\u043a\u043b\u0430 \u0447\u0438\u0441\u043b\u0430 [latex]22[\/latex] \u0440\u0430\u0432\u043d\u0430 [latex]16[\/latex].<br \/>\n\u0414\u043b\u044f \u0434\u0432\u0443\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b [latex]i[\/latex] \u0438 [latex]j[\/latex] \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u0446\u0438\u043a\u043b\u0430 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u0436\u0434\u0443 [latex]i[\/latex] \u0438 [latex]j[\/latex] \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0430\u0440\u0443 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b [latex]i[\/latex] \u0438 [latex]j[\/latex]. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 [latex]1000000[\/latex] \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 [latex]0[\/latex]. \u0421\u0447\u0438\u0442\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c [latex]32[\/latex] \u0431\u0438\u0442\u043d\u044b\u0439 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u0447\u0438\u0441\u0435\u043b [latex]i[\/latex] \u0438 [latex]j[\/latex] \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043b\u0430 [latex]i[\/latex] \u0438 [latex]j[\/latex] \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u0430\u043a\u043e\u043c \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b\u0438 \u043d\u0430 \u0432\u0445\u043e\u0434. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u0446\u0438\u043a\u043b\u0430 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u0436\u0434\u0443 [latex]i[\/latex] \u0438 [latex]j[\/latex] \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0442\u0440\u0438 \u0447\u0438\u0441\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044f \u043e\u0434\u043d\u0438\u043c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u043c.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table border=\"1\" width=\"382\">\n<tbody>\n<tr>\n<th>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<th>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<\/tr>\n<tr>\n<td>1 10<br \/>\n100 200<br \/>\n201 210<br \/>\n900 1000<\/td>\n<td>1 10 20<br \/>\n100 200 125<br \/>\n201 210 89<br \/>\n900 1000 174<\/td>\n<\/tr>\n<tr>\n<td>1 10<br \/>\n10 1<\/td>\n<td>1 10 20<br \/>\n10 1 20<\/td>\n<\/tr>\n<tr>\n<td>5 25<br \/>\n70 54<br \/>\n38 250<\/td>\n<td>5 25 24<br \/>\n70 54 113<br \/>\n38 250 128<\/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\nimport static java.lang.Math.*;\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\tint i, j, ait;\r\n\t\tScanner scan = new Scanner(System.in);\r\n\t\twhile(scan.hasNext()) {\r\n\t\t\ti = scan.nextInt();\r\n\t\t\tj = scan.nextInt();\r\n\t\t\tint it, maxIt;\r\n\t\t\tmaxIt = 0;\r\n\t\t\tfor (int a = min(i, j); a &lt;= max(i, j); a++) {\r\n\t\t\t\tit = 1;\r\n\t\t\t\tait = a;\r\n\t\t\t\twhile(ait != 1){\r\n\t\t\t\t\tif(ait % 2 == 1){\r\n\t\t\t\t\t\tait = ait * 3 + 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tait = ait \/ 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tit++;\r\n\t\t\t\t}\r\n\t\t\t\tif (it &gt; maxIt) {\r\n\t\t\t\t\tmaxIt = it;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println(i + \" \" + j + \" \" + maxIt);\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f <i><b><a href=\"https:\/\/forany.xyz\/a-54\">\u0441\u0438\u0440\u0430\u043a\u0443\u0437\u0441\u043a\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/a><\/b><\/i>.<i><b><\/b><\/i> \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0444\u0430\u043a\u0442 \u2014 \u043a\u0430\u043a\u043e\u0435 \u0431\u044b \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u0432\u0437\u044f\u0442\u044c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u041d\u0430\u043c \u0436\u0435 \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u00ab\u0434\u043b\u0438\u043d\u044b \u0446\u0438\u043a\u043b\u0430\u00bb. <b><\/b><i><b><\/b><\/i>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043f\u0430\u0440\u0443 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u0432\u0432\u043e\u0434\u0430 \u044f \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b \u00ab\u0434\u043b\u0438\u043d\u0443 \u0446\u0438\u043a\u043b\u0430\u00bb \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435. \u0418 \u0442\u0430\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b \u0447\u0438\u0441\u0435\u043b.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/submissions\/5111379\" target=\"_blank\" rel=\"noopener noreferrer\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 e-olymp.<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/r4KBWG\" target=\"_blank\" rel=\"noopener noreferrer\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 Ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b: input n print n if n = 1 then STOP if n is odd then n = 3 * n + 1 else n = n \/ 2 GOTO 2 \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f [latex]n = 22[\/latex] \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u0435\u043b: 22 11 34 17 52 26 13 40 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4868\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":134,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[216,41,134,137,145,141,75],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4868"}],"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\/134"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4868"}],"version-history":[{"count":5,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4868\/revisions"}],"predecessor-version":[{"id":4922,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4868\/revisions\/4922"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}