{"id":3994,"date":"2018-12-07T18:24:36","date_gmt":"2018-12-07T15:24:36","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=3994"},"modified":"2018-12-25T20:10:36","modified_gmt":"2018-12-25T17:10:36","slug":"e-olymp-50-%d1%80%d0%b0%d0%b7%d1%80%d0%b5%d0%b7%d0%b0%d0%bd%d0%bd%d0%be%d0%b5-%d1%87%d0%b8%d1%81%d0%bb%d0%be","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=3994","title":{"rendered":"e-olymp 50. \u0420\u0430\u0437\u0440\u0435\u0437\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u043d\u0430 \u0431\u0443\u043c\u0430\u0436\u043a\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u043b\u043e\u0441\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0447\u0438\u0441\u043b\u043e, \u043a\u0440\u0430\u0442\u043d\u043e\u0435 $d$. \u0415\u0433\u043e \u043c\u043b\u0430\u0434\u0448\u0438\u0439 \u0431\u0440\u0430\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u043b \u0447\u0438\u0441\u043b\u043e \u043d\u0430 $k$ \u0447\u0430\u0441\u0442\u0435\u0439. \u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u0440\u0435\u0448\u0438\u043b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u041e\u043d \u043f\u043e\u043c\u043d\u0438\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e $d$, \u0430 \u0447\u0438\u0441\u0435\u043b, \u043a\u0440\u0430\u0442\u043d\u044b\u0445 $d$, \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e.<br \/>\n\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0435\u043b, \u043a\u0440\u0430\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0443 $d$, \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0412\u0430\u0441\u0438\u043b\u0438\u0439, \u0435\u0441\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430 $d$ \u0438 $k$ $\\left(1 \u2264 k &lt; 9, 1 \u2264 d \u2264 100\\right)$. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 $k$ \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u0430. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0438\u0444\u0440 \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 $10.$<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table>\n<tbody>\n<tr>\n<td>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<\/tr>\n<tr>\n<tr>\n<td>$5$ $3$<br \/>\n$13$<br \/>\n$85$<br \/>\n$45$\n<\/td>\n<td>$4$<\/td>\n<\/tr>\n<tr>\n<td>$11$ $2$<br \/>\n$1$<br \/>\n$111$\n<\/td>\n<td>$1$<\/td>\n<\/tr>\n<tr>\n<td>$11$ $3$<br \/>\n$11$<br \/>\n$8$<br \/>\n$11$\n<\/td>\n<td>$0$<\/td>\n<\/tr>\n<tr>\n<td>$71$ $8$<br \/>\n$4018916609$<br \/>\n$7495223237$<br \/>\n$3405637482$<br \/>\n$3166003637$<br \/>\n$8998228133$<br \/>\n$1141886496$<br \/>\n$9124347310$<br \/>\n$7736090711$\n<\/td>\n<td>$584$<\/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 50. The cut number solution\">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Main\r\n{\r\n\tpublic static int k, d, quantity = 0;\r\n\tpublic static long[] was = new long[40320];\r\n\tpublic static long[] nums = new long[9];\r\n\tpublic static boolean Was(long h) {\r\n    \tlong c = 0;\r\n    \tfor (int i = 0; i &lt; quantity; i++) {\r\n        \tif (was[i] == h) c++;\r\n    \t}\r\n    \tif (c == 0) {\r\n        \twas[quantity] = h;\r\n        \treturn true; \r\n    \t}\r\n    \telse\r\n    \treturn false;\r\n\t}\r\n\tpublic static void Swap(int a, int b) {\r\n    \tlong t = nums[a];\r\n    \tnums[a] = nums[b];\r\n    \tnums[b] = t;\r\n\t}\r\n\tpublic static void Generate(int n) {\r\n\t    if (n == k) {\r\n\t        long sum = 0;\r\n\t        long p = 1;\r\n\t        long h = 0;\r\n\t        long hash = 1;\r\n\t        for (int i = k - 1; i &gt;= 0; i--) {\r\n\t            long subs = nums[i];\r\n\t            sum += nums[i] % d * p;\r\n\t            p *= Math.pow(10, (long)Math.log10(nums[i]) + 1);\r\n\t            p = p%d;\r\n\t            while (subs!= 0) {\r\n\t                h += subs % 10 * hash;\r\n\t                hash *= 101;\r\n\t                subs \/= 10;\r\n\t            }\r\n\t        }   \r\n\t        if (sum%d == 0 &amp;&amp; Was(h) == true) {\r\n\t            quantity++; \r\n\t        }\r\n\t    }\r\n\t    else { \r\n\t        for(int j = n; j &lt; k;j++) {\r\n\t            Swap(n,j);\r\n\t            Generate(n+1);\r\n\t            Swap(n,j);\r\n\t        }\r\n\t    }   \r\n\t}\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\td = in.nextInt();\r\n\t\tk = in.nextInt();\r\n    \tfor(int i = 0; i &lt; k; i++) {\r\n    \t\tnums[i] = in.nextLong();\r\n    \t}\r\n    \tGenerate(0);\r\n    \tSystem.out.println(quantity);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h1>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u044b \u0434\u0432\u0443\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0430 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $d$ \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 $d$, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 $d$ \u0434\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0430 \u0438\u0445 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432.  \u0410 \u0442\u0430\u043a\u0436\u0435 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0430 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $d$ \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 $d$, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 $d$ \u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0445 \u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432.<br \/>\n\u0417\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c, \u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u0431\u0435\u0440\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 $d$.<br \/>\n\u0422\u0430\u043a\u0436\u0435 \u0447\u0430\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0447\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0446\u0438\u0444\u0440\u0443 \u0443\u043c\u043d\u043e\u0436\u0438\u043c \u043d\u0430 $101^0$, \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e &#8212; \u043d\u0430 $101^1$ \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<br \/>\n\u0415\u0441\u043b\u0438 \u043d\u0430\u0448 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 $d$ \u0431\u0435\u0437 \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u0438 \u0435\u0441\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0430 $1$.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/50\" rel=\"noopener\" target=\"_blank\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 e-olymp<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/gv2pXg\" rel=\"noopener\" target=\"_blank\">\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u043d\u0430 \u0431\u0443\u043c\u0430\u0436\u043a\u0435 \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u043b\u043e\u0441\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0447\u0438\u0441\u043b\u043e, \u043a\u0440\u0430\u0442\u043d\u043e\u0435 $d$. \u0415\u0433\u043e \u043c\u043b\u0430\u0434\u0448\u0438\u0439 \u0431\u0440\u0430\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u043b \u0447\u0438\u0441\u043b\u043e \u043d\u0430 $k$ \u0447\u0430\u0441\u0442\u0435\u0439. \u0412\u0430\u0441\u0438\u043b\u0438\u0439 \u0440\u0435\u0448\u0438\u043b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u041e\u043d \u043f\u043e\u043c\u043d\u0438\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e $d$, \u0430 \u0447\u0438\u0441\u0435\u043b, \u043a\u0440\u0430\u0442\u043d\u044b\u0445 $d$, \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0435\u043b, \u043a\u0440\u0430\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0443 $d$, \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0412\u0430\u0441\u0438\u043b\u0438\u0439, \u0435\u0441\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=3994\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":131,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[125,497,498,78],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3994"}],"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\/131"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3994"}],"version-history":[{"count":5,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3994\/revisions"}],"predecessor-version":[{"id":3999,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/3994\/revisions\/3999"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}