{"id":73,"date":"2024-04-25T23:45:49","date_gmt":"2024-04-25T15:45:49","guid":{"rendered":"https:\/\/seanxd.com\/?p=73"},"modified":"2024-06-17T17:20:48","modified_gmt":"2024-06-17T09:20:48","slug":"zerojudge-a215","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a215\/","title":{"rendered":"ZeroJudge A215: Ming-ming Loves Counting"},"content":{"rendered":"<p>Ming-ming is a diligent student who loves counting. One day, his mother asked him to start counting from N. The next number would be N + 1, and then the next one would be N + 2, and so on. His mother wants to know how many numbers Mingming needs to count until the sum of all the numbers he counted exceeds M. Please help Mingming's mother.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td>The input ends with EOF. Each set of test data consists of two numbers, N and M, where the difference M \u2013 N will not exceed 10^5.<\/td><td>The output should indicate how many numbers Mingming needs to count until the sum of all the numbers he counted exceeds M.<\/td><\/tr><tr><td>1 5<br>5 10<br>100 1000<\/td><td>3<br>2<br>10<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p>Assuming N + (N+1) + (N+2) + \u2026 + (N+K) \u2265 M, use a for loop to sum all the numbers from N to N+K, where the default value of K is 1. Increase K by 1 each time the loop ends, with the termination condition set to when the sum is greater than or equal to M. Set a variable to store the sum of the numbers, initially set to N, and add N+K to it each time the loop runs. Finally, output K, which represents how many times the for loop ran.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a215\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A215: Ming-ming Loves Counting<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    int N, M;\n    while (cin &gt;&gt; N &gt;&gt; M)\n    {\n        int sum = N;\n        int K = 0;\n        for (K = 1; sum &lt;= M; K++)\n        {\n            sum += N+K;\n        }\n        cout &lt;&lt; K &lt;&lt; endl;\n    }\n}\n\n\/\/ZeroJudge A215\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u660e\u660e\u662f\u4e00\u500b\u611b\u6578\u6578\u7684\u597d\u5b78\u751f\uff0c\u9019\u5929\u5abd\u5abd\u53eb\u4ed6\u5f9e N \u958b\u59cb\u6578\uff0c\u4e0b\u4e00\u500b\u6578\u5b57\u662f N + 1\uff0c\u518d\u4e0b\u4e00\u500b\u6578\u5b57\u662f N + 2\uff0c\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[6],"tags":[13,9],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-6","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":4,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":941,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/73\/revisions\/941"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}