{"id":464,"date":"2024-05-07T09:00:00","date_gmt":"2024-05-07T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=464"},"modified":"2024-05-03T21:39:56","modified_gmt":"2024-05-03T13:39:56","slug":"zerojudge-a626","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-a626\/","title":{"rendered":"ZeroJudge A626: Prime Directive"},"content":{"rendered":"\n\n\n<p class=\"\">\u7d66\u4f60\u4e00\u500b\u6b63\u6574\u6578 N\uff0c<strong>\u8acb\u5217\u51fa\u5f9e 2 \u5230 P \u7684\u6240\u6709\u8cea\u6578<\/strong>\uff0c\u5176\u4e2d P \u70ba \u2264 N \u7684\u6700\u5927\u8cea\u6578\u3002N \u7684\u7bc4\u570d\u70ba 1 \u5230 1000\u3002\u8cea\u6578\u7684\u5b9a\u7fa9\u70ba\u53ea\u80fd\u88ab 1 \u548c\u672c\u8eab\u9664\u76e1\u7684\u5927\u65bc 1 \u7684\u6574\u6578\u3002\u8f38\u51fa\u4e2d\u6bcf\u884c\u53ea\u80fd\u6709\u4e94\u500b\u6578\u5b57\uff0c\u5982\u7bc4\u5217\u8f38\u51fa\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"is-style-regular wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7b46\u6e2c\u8cc7\u4e00\u884c\uff0c\u542b\u6709\u4e00\u500b\u6b63\u6574\u6578 N (1 \u2264 N \u2264 1000)\u3002<\/td><td>\u8f38\u51fa\u4e2d\u6bcf\u884c\u6700\u591a<strong>\u53ea\u80fd\u6709\u4e94\u500b\u6578\u5b57<\/strong>\uff0c\u5982\u7bc4\u5217\u8f38\u51fa\u3002(<strong>\u6bcf\u500b\u6578\u5b57\u542b\u5b83\u524d\u9762\u7684\u7a7a\u767d\u5171 10 \u500b\u5b57\u5143<\/strong>)<\/td><\/tr><tr><td>50<\/td><td>         2         3         5         7        11<br>        13        17        19        23        29<br>        31        37        41        43        47<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528 <strong>For\u8ff4\u5708 <\/strong>\u5224\u65b7 2 \u5230 N \u7684\u8cea\u6578\uff0c\u5224\u65b7\u5b57\u4e32\u7684\u9577\u5ea6\uff0c\u5148\u8f38\u51fa\u300c10 &#8211; \u5b57\u4e32\u9577\u5ea6\u300d\u500b\u7a7a\u767d\u5b57\u5143\uff0c\u7136\u5f8c\u8f38\u51fa\u6578\u5b57\u3002<\/p>\n\n\n\n<p class=\"\">\u9700\u8981\u7d00\u9304\u76ee\u524d\u8f38\u51fa\u7684\u6578\u5b57\u6578\u91cf\uff0c\u6bcf\u4e00\u6b21\u8f38\u51fa\u6578\u5b57\u6642\u8981 +1\uff0c\u7576\u9019\u500b\u8b8a\u6578\u70ba 5 \u6642\u9700\u8981\u63db\u884c\u4e26\u4e14\u5c07\u8b8a\u6578\u6b78\u96f6\u3002<\/p>\n\n\n\n<p class=\"\"><strong>\u6bcf\u7b46\u8cc7\u6599\u7d50\u675f\u4e4b\u5f8c\u9084\u9700\u8981\u63db\u884c\u4e00\u6b21\u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a626\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A626: Prime Directive<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;math.h&gt;\n#include &lt;map&gt;\nusing namespace std;\n\nint current = 0;\nmap&lt;int, string&gt;MAP;\n\nvoid out(string num)\n{\n    cout &lt;&lt; MAP[int(10 - num.length())] &lt;&lt; num;\n    current++;\n    if (current == 5)\n    {\n        cout &lt;&lt; &quot;\\n&quot;;\n        current = 0;\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    MAP[9] = &quot;         &quot;;\n    MAP[8] = &quot;        &quot;;\n    MAP[7] = &quot;       &quot;;\n    MAP[6] = &quot;      &quot;;\n    int N;\n    while (cin &gt;&gt; N)\n    {\n        current = 0;\n        for (int i = 2; i&lt;=N; i++)\n        {\n            bool isPrime = true;\n            for (int j = 2; j&lt;int(sqrt(i)+1); j++)\n            {\n                if (i % j == 0)\n                {\n                    isPrime = false;\n                    break;\n                }\n            }\n            if (isPrime)\n            {\n                out(to_string(i));\n            }\n        }\n        cout &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge A626\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7d66\u4f60\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u8acb\u5217\u51fa\u5f9e 2 \u5230 P \u7684\u6240\u6709\u8cea\u6578\uff0c\u5176\u4e2d P \u70ba \u2264 N \u7684\u6700\u5927\u8cea\u6578\u3002N \u7684\u7bc4\u570d\u70ba 1 \u5230  [&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":[29],"tags":[14,8,11,13,9],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-map","tag-8","tag-11","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=464"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/464\/revisions\/465"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}