{"id":731,"date":"2016-07-01T14:21:56","date_gmt":"2016-07-01T11:21:56","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=731"},"modified":"2016-07-06T10:42:05","modified_gmt":"2016-07-06T07:42:05","slug":"e-olymp-141-minimum-amount-of-digits","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=731","title":{"rendered":"e-olymp 141. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0446\u0438\u0444\u0440"},"content":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u0437\u044f\u0442\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430\u00a0<a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/141\" target=\"_blank\">www.e-olymp.com<\/a><\/p>\n<p><strong>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/strong><\/p>\n<p>\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 [latex][M,N][\/latex] \u0438\u043c\u0435\u044e\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0446\u0438\u0444\u0440 ?<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<p>\u0412\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430 [latex]M[\/latex] \u0438 [latex]N[\/latex], [latex]1\\le M\\le N\\le 1000000[\/latex].<\/p>\n<p><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:<\/strong><\/p>\n<p>\u0412 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0430\u0439\u043b \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u2013 \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e.<\/p>\n<p><strong>\u0422\u0435\u0441\u0442\u044b<\/strong><\/p>\n<table style=\"height: 194px\" width=\"312\">\n<tbody>\n<tr>\n<td style=\"width: 70px;text-align: center\">\u2116<\/td>\n<td style=\"width: 70px;text-align: center\">M<\/td>\n<td style=\"width: 72px;text-align: center\">N<\/td>\n<td style=\"width: 72px;text-align: center\">\u0412\u044b\u0432\u043e\u0434<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 70px;text-align: center\">1<\/td>\n<td style=\"width: 70px;text-align: center\">1<\/td>\n<td style=\"width: 72px;text-align: center\">100<\/td>\n<td style=\"width: 72px;text-align: center\">3<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 70px;text-align: center\">2<\/td>\n<td style=\"width: 70px;text-align: center\">2<\/td>\n<td style=\"width: 72px;text-align: center\">17<\/td>\n<td style=\"width: 72px;text-align: center\">1<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 70px;text-align: center\">3<\/td>\n<td style=\"width: 70px;text-align: center\">32<\/td>\n<td style=\"width: 72px;text-align: center\">1024<\/td>\n<td style=\"width: 72px;text-align: center\">2<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 70px;text-align: center\">4<\/td>\n<td style=\"width: 70px;text-align: center\">1<\/td>\n<td style=\"width: 72px;text-align: center\">1000000<\/td>\n<td style=\"width: 72px;text-align: center\">7<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 70px;text-align: center\">5<\/td>\n<td style=\"width: 70px;text-align: center\">10<\/td>\n<td style=\"width: 72px;text-align: center\">10<\/td>\n<td style=\"width: 72px;text-align: center\">1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/strong><\/p>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\n\r\nclass Main {\r\n\t\r\n\tpublic static void main (String[] args) throws java.lang.Exception {\r\n\t\t\r\n\t\tint sumMin, counter = 1;\r\n\t\t\r\n\t\tScanner scanner = new Scanner(System.in);\r\n\t\tint m = scanner.nextInt();\r\n\t\tint n = scanner.nextInt();\r\n\t\t\r\n\t\tsumMin = sumOfDigits(m);\r\n\t\t\r\n\t\tfor(int i = m + 1; i &lt;= n; i++) {\r\n\t\t\tif (sumOfDigits(i) &lt; sumMin) {\r\n\t\t\t\tsumMin = sumOfDigits(i);\r\n\t\t\t\tcounter = 1;\r\n\t\t\t} else if (sumOfDigits(i) == sumMin)   \r\n\t\t    counter++;\r\n\t\t}\r\n\t\tSystem.out.println(counter);\r\n\t}\r\n\t\r\n\tpublic static int sumOfDigits(int a){\r\n\t\tint sum = 0;\r\n\t\twhile (a &gt; 0) {\r\n\t\t\tsum += a%10;\r\n\t\t\ta \/= 10;\r\n\t\t}\r\n\treturn sum;\r\n\t}\r\n}<\/pre>\n<p><a href=\"http:\/\/ideone.com\/t0hEaV\" target=\"_blank\">www.ideone.com<\/a><\/p>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/strong><br \/>\n\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u0447\u0438\u0441\u0435\u043b \u0432\u0432\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043d\u0430\u043c\u0438 \u0447\u0438\u0441\u043b\u0430. \u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0433\u0440\u0430\u043d\u0438\u0446 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 [latex](sumMin)[\/latex] \u0441\u0443\u043c\u043c\u0435 \u0446\u0438\u0444\u0440 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 [latex]M[\/latex], \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u043e\u0439 \u0446\u0438\u0444\u0440 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u0435\u043d 1. \u0412 \u0446\u0438\u043a\u043b\u0435 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0446\u0438\u0444\u0440 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0447\u0438\u0441\u043b\u0430, \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e \u0441 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0443\u043c\u043c\u043e\u0439 \u0446\u0438\u0444\u0440, \u0437\u043d\u0430\u0447\u0438\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u0430 \u0441\u0443\u043c\u043c\u0430 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439, \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 [latex]sumMin[\/latex]. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0441\u0443\u043c\u043c\u0430 \u0446\u0438\u0444\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0432\u043d\u0430 [latex]sumMin[\/latex], \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a. \u041e\u043d \u0438 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0435, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0446\u0438\u0444\u0440.<br \/>\n\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/www.e-olymp.com\/ru\/submissions\/2712275\">e-olymp.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u0437\u044f\u0442\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430\u00a0www.e-olymp.com \u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438: \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 [latex][M,N][\/latex] \u0438\u043c\u0435\u044e\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0446\u0438\u0444\u0440 ? \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: \u0412\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430 [latex]M[\/latex] \u0438 [latex]N[\/latex], [latex]1\\le M\\le N\\le 1000000[\/latex]. \u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: \u0412 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0430\u0439\u043b \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u2013 \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e. \u0422\u0435\u0441\u0442\u044b \u2116 M N \u0412\u044b\u0432\u043e\u0434 1 1 100 3 2 2 17 1 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=731\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":82,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[100,99,75],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/731"}],"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\/82"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=731"}],"version-history":[{"count":6,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":906,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions\/906"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}