{"id":4967,"date":"2020-09-09T22:47:07","date_gmt":"2020-09-09T19:47:07","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4967"},"modified":"2020-11-25T11:58:14","modified_gmt":"2020-11-25T08:58:14","slug":"e-olymp-9036-%d0%ba%d0%be%d0%bc%d0%b1%d0%b8%d0%bd%d0%b0%d1%86%d0%b8%d1%8f-%d0%b8%d0%b3%d1%80%d0%b0%d0%bb%d1%8c%d0%bd%d1%8b%d1%85-%d0%ba%d0%be%d1%81%d1%82%d0%b5%d0%b9","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4967","title":{"rendered":"e-olymp 9036. \u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u0438\u0433\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u0441\u0442\u0435\u0439"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u041f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 $n$ \u0431\u0440\u043e\u0441\u0430\u044f \u0438\u0433\u0440\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0443\u0431\u0438\u043a \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u0440\u043e\u0441\u043e\u043a \u0434\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0435\u0436\u0434\u0443 <strong>1<\/strong>\u00a0\u0438\u00a0<strong>6<\/strong>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 $n = 3$, \u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f\u00a0<strong>4<\/strong>\u00a0\u0441\u043f\u043e\u0441\u043e\u0431\u0430:<br \/>\n<strong>1<\/strong>\u00a0+\u00a0<strong>1<\/strong>\u00a0+\u00a0<strong>1<\/strong><br \/>\n<strong>1<\/strong>\u00a0+\u00a0<strong>2<\/strong><br \/>\n<strong>2<\/strong>\u00a0+\u00a0<strong>1<\/strong><br \/>\n<strong>3<\/strong><\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u041e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $n$ $(1 \\leqslant n \\leqslant 10^6)$.<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e\u00a0$10^9+7$.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table style=\"height: 282px\" width=\"1028\">\n<tbody>\n<tr>\n<td>\u2116<\/td>\n<td style=\"text-align: left\">\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td style=\"text-align: left\">\u00a0\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">1<\/td>\n<td style=\"text-align: left\">1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>3<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>5<\/td>\n<td>16<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>6<\/td>\n<td>32<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>8<\/td>\n<td>123<\/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 java.util.Scanner;\r\npublic class Ideone\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tint n;\r\n\t    int ans = 0;\r\n\t    Scanner myObj = new Scanner(System.in);\r\n\t    n = myObj.nextInt(); \/\/\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a\r\n\t    int a[] = new int[n+1]; \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\r\n\t    Arrays.fill(a, 0);\r\n\t    if (n == 1) ans = 1;\r\n\t    if (n == 2) ans = 2;\r\n\t    if (n == 3) ans = 4;\r\n\t    if (n == 4) ans = 8;\r\n\t    if (n == 5) ans = 16;\r\n\t    if (n == 6) ans = 32;\r\n\t    \/\/ \u0447\u0430\u0441\u0442\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438\r\n\t    \r\n\t    if (n &gt; 6)\r\n\t    {\r\n\t        a[1] = 1; \r\n\t        a[2] = 2; \r\n\t        a[3] = 4; \r\n\t        a[4] = 8;\r\n\t        a[5] = 16; \r\n\t        a[6] = 32; \r\n\t        for (int i = 7; i &lt; n + 1; i++)\r\n\t        {\r\n\t            a[i]=0;\r\n\t            for (int j = 1; j &lt; 7; j++) \/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u043b\u044f i-\u043e\u0439 \u0441\u0443\u043c\u043c\u044b\r\n\t                a[i] = ( a[i] + a[i-j] ) % 1000000007;\r\n\t        }\r\n\t        ans = a[n];\r\n\t    }\r\n\t    \r\n\t    System.out.println(ans);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430 $n+1$ \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0412 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0441\u0443\u043c\u043c 1,2..,6. \u0414\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 $n&gt;7$ \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0434\u0435\u0435\u0439. \u0411\u0443\u0434\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0441\u0443\u043c\u043c, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 7 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u043e\u0439\u0434\u0435\u043c \u0434\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043c $n$. \u0411\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e \u0442\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 $a_{i}=a_{i-1}+a_{i-2}+a_{i-3}+a_{i-4}+a_{i-5}+a_{i-6}$\u00a0 . \u0414\u043b\u044f \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0435\u0441\u0442\u0438 \u0441\u0443\u043c\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u043e \u044d\u0442\u043e\u0439 \u0436\u0435 \u0444\u043e\u0440\u043c\u0443\u043b\u0435, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c, \u0447\u0442\u043e $0 &lt; i-k \\; (1 \\leqslant k \\leqslant 6)$ \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0435\u0449\u0435 1 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 ( $i$ ), \u043f\u043e\u0434\u0431\u0440\u043e\u0441\u0438\u0432 \u043a\u0443\u0431\u0438\u043a 1 \u0440\u0430\u0437. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043b\u044f $n=7$. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c 7 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0434\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043a\u0443\u0431\u0438\u043a \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043b\u044f $n$ \u043e\u0442 1 \u0434\u043e 6. \u0415\u0441\u043b\u0438 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 1, \u0442\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f $a_{6}$ \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a, \u0435\u0441\u043b\u0438 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 2, \u0442\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f\u00a0 $a_{5}$\u00a0 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0417\u0430\u0442\u0435\u043c \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0443\u0431\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u0430\u0441\u0442\u044c 6 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f $n=8$ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u0441\u044f \u043d\u0430\u00a0 $a_{7}$ \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u0441\u044f \u043d\u0430\u00a0 $a_{1}$, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0443\u0431\u0438\u043a \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 6 \u0433\u0440\u0430\u043d\u0435\u0439.<\/p>\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 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/9036\" target=\"_blank\" rel=\"noopener noreferrer\">e-olymp<\/a><\/p>\n<p>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430 <a href=\"https:\/\/ideone.com\/oT0YSy\" target=\"_blank\" rel=\"noopener noreferrer\">ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 $n$ \u0431\u0440\u043e\u0441\u0430\u044f \u0438\u0433\u0440\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0443\u0431\u0438\u043a \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u0440\u043e\u0441\u043e\u043a \u0434\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0435\u0436\u0434\u0443 1\u00a0\u0438\u00a06. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 $n = 3$, \u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f\u00a04\u00a0\u0441\u043f\u043e\u0441\u043e\u0431\u0430: 1\u00a0+\u00a01\u00a0+\u00a01 1\u00a0+\u00a02 2\u00a0+\u00a01 3 \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u041e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $n$ $(1 \\leqslant n \\leqslant 10^6)$. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e\u00a0$10^9+7$. \u0422\u0435\u0441\u0442\u044b \u2116 \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4967\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":142,"featured_media":5073,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[517,489,135,518],"jetpack_featured_media_url":"https:\/\/java.mazurok.com\/wp-content\/uploads\/981d85dfabd8558364f25e77a7b6d1a11.jpg","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4967"}],"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\/142"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4967"}],"version-history":[{"count":1,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4967\/revisions"}],"predecessor-version":[{"id":4978,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4967\/revisions\/4978"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/media\/5073"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}