{"id":74,"date":"2011-09-21T13:27:24","date_gmt":"2011-09-21T04:27:24","guid":{"rendered":"http:\/\/tech.fuqinho.net\/?p=74"},"modified":"2011-09-21T13:27:24","modified_gmt":"2011-09-21T04:27:24","slug":"gcj-japan-2011-%e7%b7%b4%e7%bf%92%e5%95%8f%e9%a1%8c%e6%95%b0%e3%81%ae%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/tech.fuqinho.net\/?p=74","title":{"rendered":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408"},"content":{"rendered":"<p>\t\t\t\t\u8077\u5834\u306e\u5148\u8f29\u304cLarge\u306e\u7b54\u3048\u304c\u5408\u308f\u306a\u3044\u3063\u3066\u8a00\u3063\u3066\u305f\u306e\u3067\u50d5\u3082\u89e3\u3044\u3066\u307f\u305f\u3002<\/p>\n<p>\u3084\u308a\u65b9\u306f\u3001\u4f8b\u3048\u3070sample\u306e\u901a\u308a10-20\u306e\u533a\u9593\u3067P=3\u306e\u5834\u5408\u3001<\/p>\n<ol>\n<li>3\u306e\u500d\u657012,15,18\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u6bb5\u968e\u3067\u30b0\u30eb\u30fc\u30d7\u6570\u306f-3<\/li>\n<li>\u53d6\u308a\u51fa\u3057\u305f\u6570\u306f\u5168\u90e8\u72ec\u7acb\u3057\u3066\u305f\u306e\u3067\u3001\u65b0\u305f\u306b\u30b0\u30eb\u30fc\u30d7\u304c1\u3064\u3067\u304d\u308b\u3002\u30b0\u30eb\u30fc\u30d7\u6570+1<\/li>\n<li>5\u306e\u500d\u657010,15,20\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u6bb5\u968e\u3067\u30b0\u30eb\u30fc\u30d7\u6570\u306f-2\u3002(15\u306f\u72ec\u7acb\u3057\u3066\u306a\u3044\u306e\u3067\u53d6\u308a\u51fa\u3057\u3066\u3082\u30b0\u30eb\u30fc\u30d7\u304c\u6e1b\u3089\u306a\u3044\u3002\u3060\u304b\u3089-3\u3058\u3083\u306a\u3044\u3002)<\/li>\n<li>\u65e2\u306b\u30b0\u30eb\u30fc\u30d7\u306b\u5165\u3063\u3066\u308b15\u3092\u542b\u3080\u306e\u3067\u3001\u65b0\u305f\u306b\u30b0\u30eb\u30fc\u30d7\u306f\u51fa\u6765\u306a\u3044(\u7d71\u5408\u3055\u308c\u308b)\u3002\u30b0\u30eb\u30fc\u30d7\u6570+0<\/li>\n<\/ol>\n<p>\u307f\u305f\u3044\u306a\u611f\u3058\u306e\u64cd\u4f5c\u3092\u7e70\u308a\u8fd4\u3059\u3002<br \/>\n\u3069\u306e\u6570\u304c\u3069\u3046\u30b0\u30eb\u30fc\u30d4\u30f3\u30b0\u3055\u308c\u308b\u304b\u306f\u6c17\u306b\u305b\u305a\u3001\u6570\u306e\u5897\u6e1b\u3060\u3051\u898b\u308b\u5f62\u3067\u3001\u5b9f\u884c\u6642\u9593\u306f10\u79d2\u304f\u3089\u3044\u3002<\/p>\n<p>\u7d50\u679c\u2026\u3000\u305c\u3093\u305c\u3093\u9055\u3046\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u5148\u8f29\u3068\u7b54\u3048\u304c\u4e00\u81f4\u3057\u3066\u3001GCJ\u306e\u30b7\u30b9\u30c6\u30e0\u304b\u3089\u306f\u4e0d\u6b63\u89e3\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3042\u3063\u308c\u30fc\uff1f\u4e8c\u4eba\u3057\u3066\u306a\u3093\u304b\u7279\u6b8a\u306a\u30b1\u30fc\u30b9\u3092\u898b\u843d\u3068\u3057\u3066\u308b\u306e\u304b\u306a\u3002<\/p>\n<p>[cpp]<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<br \/>\nusing namespace std;<\/p>\n<p>static const int MAX_PRIME_NUMBER = 1000000;<\/p>\n<p>int solve(vector&lt;int&gt;&amp; primes, long long A, long long B, int P) {<br \/>\n    int result = B &#8211; A + 1;<br \/>\n    vector&lt;bool&gt; grouped(B &#8211; A + 1, false);<br \/>\n    for (int i = 0; i &lt; primes.size(); i++) {<br \/>\n        int divisor = primes[i];<br \/>\n        if (divisor &gt;= P &amp;&amp; divisor &lt; B &#8211; A + 1) {<br \/>\n            int remNum = 0;<br \/>\n            int addNum = 0;<br \/>\n            bool isInOtherGroup = false;<br \/>\n            int first = (A % divisor == 0 ? 0 : (divisor &#8211; A % divisor));<br \/>\n            for (int j = first; j &lt; grouped.size(); j += divisor) {<br \/>\n                if (!grouped[j]) {<br \/>\n                    remNum++;<br \/>\n                    grouped[j] = true;<br \/>\n                } else {<br \/>\n                    isInOtherGroup = true;<br \/>\n                }<br \/>\n            }<br \/>\n            if (!isInOtherGroup) {<br \/>\n                addNum = 1;<br \/>\n            }<br \/>\n            result -= remNum &#8211; addNum;<br \/>\n        }<br \/>\n    }<br \/>\n    return result;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    \/\/ prepare prime numbers<br \/>\n    vector&lt;int&gt; primes;<br \/>\n    vector&lt;bool&gt; temp(MAX_PRIME_NUMBER + 1, true);<br \/>\n    for (int i = 2; i &lt;= MAX_PRIME_NUMBER; i++) {<br \/>\n        if (temp[i]) {<br \/>\n            primes.push_back(i);<br \/>\n            for (int j = i; j &lt;= MAX_PRIME_NUMBER; j += i) {<br \/>\n                temp[j] = false;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ read cases from standard input and print result to standard out<br \/>\n    int N, P;<br \/>\n    long long A, B;<br \/>\n    cin &gt;&gt; N;<br \/>\n    for (int i = 1; i &lt;= N; i++) {<br \/>\n        cin &gt;&gt; A &gt;&gt; B &gt;&gt; P;<br \/>\n        int result = solve(primes, A, B, P);<br \/>\n        cout &lt;&lt; &quot;Case #&quot; &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; result &lt;&lt; endl;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<br \/>\n[\/cpp]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8077\u5834\u306e\u5148\u8f29\u304cLarge\u306e\u7b54\u3048\u304c\u5408\u308f\u306a\u3044\u3063\u3066\u8a00\u3063\u3066\u305f\u306e\u3067\u50d5\u3082\u89e3\u3044\u3066\u307f\u305f\u3002 \u3084\u308a\u65b9\u306f\u3001\u4f8b\u3048\u3070sample\u306e\u901a\u308a10-20\u306e\u533a\u9593\u3067P=3\u306e\u5834\u5408\u3001 3\u306e\u500d\u657012,15,18\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u6bb5\u968e\u3067\u30b0\u30eb\u30fc\u30d7\u6570\u306f-3 \u53d6\u308a\u51fa\u3057\u305f\u6570\u306f\u5168 &#8230; <a title=\"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408\" class=\"read-more\" href=\"https:\/\/tech.fuqinho.net\/?p=74\" aria-label=\"\u8a73\u7d30\u306f\u3053\u3061\u3089 GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[2],"tags":[5,7],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-2","tag-cpp","tag-googlecodejam"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tech.fuqinho.net\/?p=74\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder\" \/>\n<meta property=\"og:description\" content=\"\u8077\u5834\u306e\u5148\u8f29\u304cLarge\u306e\u7b54\u3048\u304c\u5408\u308f\u306a\u3044\u3063\u3066\u8a00\u3063\u3066\u305f\u306e\u3067\u50d5\u3082\u89e3\u3044\u3066\u307f\u305f\u3002 \u3084\u308a\u65b9\u306f\u3001\u4f8b\u3048\u3070sample\u306e\u901a\u308a10-20\u306e\u533a\u9593\u3067P=3\u306e\u5834\u5408\u3001 3\u306e\u500d\u657012,15,18\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u6bb5\u968e\u3067\u30b0\u30eb\u30fc\u30d7\u6570\u306f-3 \u53d6\u308a\u51fa\u3057\u305f\u6570\u306f\u5168 ... \u7d9a\u304d\u3092\u8aad\u3080\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tech.fuqinho.net\/?p=74\" \/>\n<meta property=\"og:site_name\" content=\"Happy Coder\" \/>\n<meta property=\"article:published_time\" content=\"2011-09-21T04:27:24+00:00\" \/>\n<meta name=\"author\" content=\"fuqinho\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"fuqinho\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74#article\",\"isPartOf\":{\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74\"},\"author\":{\"name\":\"fuqinho\",\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7\"},\"headline\":\"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408\",\"datePublished\":\"2011-09-21T04:27:24+00:00\",\"dateModified\":\"2011-09-21T04:27:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74\"},\"wordCount\":242,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7\"},\"keywords\":[\"Cpp\",\"GoogleCodeJam\"],\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/tech.fuqinho.net\/?p=74#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74\",\"url\":\"https:\/\/tech.fuqinho.net\/?p=74\",\"name\":\"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder\",\"isPartOf\":{\"@id\":\"https:\/\/tech.fuqinho.net\/#website\"},\"datePublished\":\"2011-09-21T04:27:24+00:00\",\"dateModified\":\"2011-09-21T04:27:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tech.fuqinho.net\/?p=74\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tech.fuqinho.net\/?p=74#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u30db\u30fc\u30e0\",\"item\":\"https:\/\/tech.fuqinho.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tech.fuqinho.net\/#website\",\"url\":\"https:\/\/tech.fuqinho.net\/\",\"name\":\"Happy Coder\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tech.fuqinho.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"ja\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7\",\"name\":\"fuqinho\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tech.fuqinho.net\/wp-content\/uploads\/2023\/02\/hatena-block_400x400.png\",\"contentUrl\":\"https:\/\/tech.fuqinho.net\/wp-content\/uploads\/2023\/02\/hatena-block_400x400.png\",\"width\":400,\"height\":400,\"caption\":\"fuqinho\"},\"logo\":{\"@id\":\"https:\/\/tech.fuqinho.net\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/tech.fuqinho.net\"],\"url\":\"https:\/\/tech.fuqinho.net\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tech.fuqinho.net\/?p=74","og_locale":"ja_JP","og_type":"article","og_title":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder","og_description":"\u8077\u5834\u306e\u5148\u8f29\u304cLarge\u306e\u7b54\u3048\u304c\u5408\u308f\u306a\u3044\u3063\u3066\u8a00\u3063\u3066\u305f\u306e\u3067\u50d5\u3082\u89e3\u3044\u3066\u307f\u305f\u3002 \u3084\u308a\u65b9\u306f\u3001\u4f8b\u3048\u3070sample\u306e\u901a\u308a10-20\u306e\u533a\u9593\u3067P=3\u306e\u5834\u5408\u3001 3\u306e\u500d\u657012,15,18\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u6bb5\u968e\u3067\u30b0\u30eb\u30fc\u30d7\u6570\u306f-3 \u53d6\u308a\u51fa\u3057\u305f\u6570\u306f\u5168 ... \u7d9a\u304d\u3092\u8aad\u3080","og_url":"https:\/\/tech.fuqinho.net\/?p=74","og_site_name":"Happy Coder","article_published_time":"2011-09-21T04:27:24+00:00","author":"fuqinho","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"fuqinho","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"1\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/tech.fuqinho.net\/?p=74#article","isPartOf":{"@id":"https:\/\/tech.fuqinho.net\/?p=74"},"author":{"name":"fuqinho","@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7"},"headline":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408","datePublished":"2011-09-21T04:27:24+00:00","dateModified":"2011-09-21T04:27:24+00:00","mainEntityOfPage":{"@id":"https:\/\/tech.fuqinho.net\/?p=74"},"wordCount":242,"commentCount":0,"publisher":{"@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7"},"keywords":["Cpp","GoogleCodeJam"],"inLanguage":"ja","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/tech.fuqinho.net\/?p=74#respond"]}]},{"@type":"WebPage","@id":"https:\/\/tech.fuqinho.net\/?p=74","url":"https:\/\/tech.fuqinho.net\/?p=74","name":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408 - Happy Coder","isPartOf":{"@id":"https:\/\/tech.fuqinho.net\/#website"},"datePublished":"2011-09-21T04:27:24+00:00","dateModified":"2011-09-21T04:27:24+00:00","breadcrumb":{"@id":"https:\/\/tech.fuqinho.net\/?p=74#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tech.fuqinho.net\/?p=74"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/tech.fuqinho.net\/?p=74#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u30db\u30fc\u30e0","item":"https:\/\/tech.fuqinho.net\/"},{"@type":"ListItem","position":2,"name":"GCJ Japan 2011 \u7df4\u7fd2\u554f\u984c\/\u6570\u306e\u96c6\u5408"}]},{"@type":"WebSite","@id":"https:\/\/tech.fuqinho.net\/#website","url":"https:\/\/tech.fuqinho.net\/","name":"Happy Coder","description":"","publisher":{"@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tech.fuqinho.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"ja"},{"@type":["Person","Organization"],"@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/3f5c2a20c9acba8360c501cb7038a4e7","name":"fuqinho","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/image\/","url":"https:\/\/tech.fuqinho.net\/wp-content\/uploads\/2023\/02\/hatena-block_400x400.png","contentUrl":"https:\/\/tech.fuqinho.net\/wp-content\/uploads\/2023\/02\/hatena-block_400x400.png","width":400,"height":400,"caption":"fuqinho"},"logo":{"@id":"https:\/\/tech.fuqinho.net\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/tech.fuqinho.net"],"url":"https:\/\/tech.fuqinho.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":0,"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.fuqinho.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}