{"id":4601,"date":"2018-12-27T21:03:07","date_gmt":"2018-12-27T18:03:07","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4601"},"modified":"2018-12-27T23:24:31","modified_gmt":"2018-12-27T20:24:31","slug":"e-olymp-263-%d1%82%d1%80%d0%b8-%d0%b5%d0%b4%d0%b8%d0%bd%d0%b8%d1%86%d1%8b","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4601","title":{"rendered":"e-olymp 263. \u0422\u0440\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u044b"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u0438\u043d\u044b $n,$ \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0443\u043b\u0435\u0439 \u0438 \u0435\u0434\u0438\u043d\u0438\u0446, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u043f\u043e\u0434\u0440\u044f\u0434.<\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0414\u043b\u0438\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439  $n$ $\\left ( 1 \\leq n \\leq 10^{5} \\right ).$<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e $12345.$<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table>\n<tbody>\n<tr>\n<td><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<td><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<\/tr>\n<tr>\n<td>$1$<\/td>\n<td>$2$<\/td>\n<\/tr>\n<tr>\n<td>$4$<\/td>\n<td>$0$<\/td>\n<\/tr>\n<tr>\n<td>$263$<\/td>\n<td>$10159$<\/td>\n<\/tr>\n<tr>\n<td>$10000$<\/td>\n<td>$8872$<\/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\tstatic int MAX = 100010;\r\n\tstatic int f[] = new int[MAX];\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\tf[1] = 2; \r\n\t\tf[2] = 4; \r\n\t\tf[3] = 7;\r\n\t\tfor(int i = 4; i &lt;= n; i++) {\r\n\t\t\tf[i] = (f[i-1] + f[i-2] + f[i-3]) % 12345;\r\n\t\t}\r\n\t\tSystem.out.println(f[n]);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u041e\u0431\u044a\u044f\u0432\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 $f,$ \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f $f(1), f(2),\\dots, f(n).$ \u0414\u0430\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 $f$ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f $f(1), f(2)$ \u0438 $f(3).$ \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f $f(i)$ \u043f\u043e \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 $f(n) = f(n \u2013 1) + f(n \u2013 2) + f(n \u2013 3).$<br \/>\n\u042d\u0442\u0443 \u0444\u043e\u0440\u043c\u0443\u043b\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0442\u0430\u043a: \u0441\u043f\u0435\u0440\u0432\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 $f(n)$ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0438\u0437 $0$ \u0438 $1$ \u0434\u043b\u0438\u043d\u044b $n.$ \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0435\u0441\u043b\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f $0,$ \u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c $f(n \u2013 1)$ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0415\u0441\u043b\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 $1,$ \u0442\u043e \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430. \u0415\u0441\u043b\u0438 \u0442\u0430\u043c \u0441\u0442\u043e\u0438\u0442 $0,$ \u0442\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 $n \u2013 2 $\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c $f(n \u2013 2)$ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 $1,$ \u0442\u043e \u043d\u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u043c\u0435\u0441\u0442\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f $0$ \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c $f(n \u2013 3)$ \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<br \/>\n\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f $f(i)$ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e $12345.$ \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e.<\/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\/263\" rel=\"noopener\" target=\"_blank\">e-olymp<\/a><\/p>\n<p>\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <a href=\"https:\/\/ideone.com\/uclf2e\" rel=\"noopener\" target=\"_blank\">ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u0438\u043d\u044b $n,$ \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0443\u043b\u0435\u0439 \u0438 \u0435\u0434\u0438\u043d\u0438\u0446, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u043f\u043e\u0434\u0440\u044f\u0434. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0414\u043b\u0438\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 $n$ $\\left ( 1 \\leq n \\leq 10^{5} \\right ).$ \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e $12345.$ \u0422\u0435\u0441\u0442\u044b \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$ $2$ $4$ $0$ $263$ $10159$ $10000$ $8872$ &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4601\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":124,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,108],"tags":[348,659,139,394],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4601"}],"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\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4601"}],"version-history":[{"count":3,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4601\/revisions"}],"predecessor-version":[{"id":4668,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4601\/revisions\/4668"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}