{"id":4613,"date":"2018-12-27T19:23:20","date_gmt":"2018-12-27T16:23:20","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4613"},"modified":"2018-12-27T19:42:35","modified_gmt":"2018-12-27T16:42:35","slug":"e-olymp-3843-%d0%bf%d1%80%d0%be%d1%81%d1%82%d1%8b%d0%b5","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4613","title":{"rendered":"e-olymp 3843. \u041f\u0440\u043e\u0441\u0442\u044b\u0435"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u041f\u0443\u0441\u0442\u044c $m$ \u0438 $n$ $\\left(2 \u2264 m &lt; n \u2264 107\\right)$ \u2014 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/p>\n<p><strong>Prime<\/strong> $\\left(m, n\\right) = \\lbrace{ p | p\\;\u043f\u0440\u043e\u0441\u0442\u043e\u0435, m \u2264 p \u2264 n \\rbrace}$.<\/p>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <strong>Prime<\/strong>$\\left(m, n\\right)$.<\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432. \u0414\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u044b \u0447\u0438\u0441\u043b\u0430 $m$ \u0438 $n$.<\/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\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <strong>Prime<\/strong>$\\left(m, n\\right)$.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table>\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 style=\"text-align: left\">2 20<\/p>\n<p>70 110<\/p>\n<p>5 150<\/td>\n<td style=\"text-align: center\">8<\/p>\n<p>10<\/p>\n<p>33<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">7 2056<\/p>\n<p>14 181<\/p>\n<p>27 367<\/td>\n<td style=\"text-align: center\">307<\/p>\n<p>36<\/p>\n<p>64<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">77 777<\/p>\n<p>55 555<\/p>\n<p>33 333<\/td>\n<td style=\"text-align: center\">116<\/p>\n<p>85<\/p>\n<p>56<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h1>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nimport java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\nclass Main\r\n{\r\n  public static void main (String[] args) throws java.lang.Exception\r\n  {\r\n     \r\n     Scanner in = new Scanner(System.in);\r\n    \r\n     final int MAXN = 10000001;\r\n     int simple[]=new int[MAXN+1];\r\n     for(int i = 2; i &lt;= MAXN; i++){\r\n         simple[i] = 1;\r\n     }\r\n     for(int i = 2; i &lt;= Math.sqrt(MAXN); i++){\r\n         if(simple[i]==1){\r\n             for(int j = i * i; j &lt;= MAXN; j += i){\r\n                 simple[j] = 0;\r\n             }\r\n         }\r\n     }\r\n \r\n     int count[]=new int[MAXN+1];\r\n     int lastSum = 0;\r\n     for(int i = 1; i &lt; MAXN; i++){\r\n         count[i] = lastSum + simple[i];\r\n         lastSum = count[i];\r\n     }\r\n      while(in.hasNextInt()) {\r\n        int m = in.nextInt();\r\n    int n = in.nextInt();\r\n        int answer = count[n] - count[m] + simple[m];\r\n        System.out.println();\r\n      System.out.println(answer);\r\n      }\r\n  }\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0441\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0438\u043f\u0430 <code>bool<\/code> \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0435\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code>. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043b\u0438 \u0447\u0438\u0441\u043b\u043e, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0442\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>false<\/code>.<br \/>\n\u0417\u0430\u0442\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 <code>n<\/code> \u0434\u043e <code>m<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430-\u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430: \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.<br \/>\n\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432 \u0446\u0438\u043a\u043b\u0435 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0432\u0435\u0442 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/3843\" target=\"_blank\" rel=\"noopener\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 E-olymp<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/pdePI3\" target=\"_blank\" rel=\"noopener\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041f\u0443\u0441\u0442\u044c $m$ \u0438 $n$ $\\left(2 \u2264 m &lt; n \u2264 107\\right)$ \u2014 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e: Prime $\\left(m, n\\right) = \\lbrace{ p | p\\;\u043f\u0440\u043e\u0441\u0442\u043e\u0435, m \u2264 p \u2264 n \\rbrace}$. \u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 Prime$\\left(m, n\\right)$. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432. \u0414\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4613\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":125,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[639,640,141,641],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4613"}],"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\/125"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4613"}],"version-history":[{"count":2,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4613\/revisions"}],"predecessor-version":[{"id":4617,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4613\/revisions\/4617"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}