{"id":241,"date":"2017-03-14T17:31:29","date_gmt":"2017-03-14T09:31:29","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=241"},"modified":"2017-03-14T17:31:29","modified_gmt":"2017-03-14T09:31:29","slug":"1163","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2017\/03\/14\/1163\/","title":{"rendered":"\u4e5d\u5ea6\u9898\u76ee1163\uff1a\u7d20\u6570"},"content":{"rendered":"<p>\u8fd9\u91cc\u5206\u4eab\u7684\u662f\u4e00\u4e9b\u6211\u505a\u8fc7\u76844\u661f\u3001\u4e94\u661f\uff0c\u4ee5\u53ca\u6211\u603b\u662f\u63d0\u4ea4\u8d85\u8fc73\u6b21\u7684\u9898\u76ee\u3002<\/p>\n<p>\u9898\u76ee\u63cf\u8ff0\uff1a<br \/>\n\u8f93\u5165\u4e00\u4e2a\u6574\u6570n(2<=n<=10000)\uff0c\u8981\u6c42\u8f93\u51fa\u6240\u6709\u4ece1\u5230\u8fd9\u4e2a\u6574\u6570\u4e4b\u95f4(\u4e0d\u5305\u62ec1\u548c\u8fd9\u4e2a\u6574\u6570)\u4e2a\u4f4d\u4e3a1\u7684\u7d20\u6570\uff0c\u5982\u679c\u6ca1\u6709\u5219\u8f93\u51fa-1\u3002\n\u8f93\u5165\uff1a\n\u8f93\u5165\u6709\u591a\u7ec4\u6570\u636e\u3002\n\u6bcf\u7ec4\u4e00\u884c\uff0c\u8f93\u5165n\u3002\n\u8f93\u51fa\uff1a\n\u8f93\u51fa\u6240\u6709\u4ece1\u5230\u8fd9\u4e2a\u6574\u6570\u4e4b\u95f4(\u4e0d\u5305\u62ec1\u548c\u8fd9\u4e2a\u6574\u6570)\u4e2a\u4f4d\u4e3a1\u7684\u7d20\u6570(\u7d20\u6570\u4e4b\u95f4\u7528\u7a7a\u683c\u9694\u5f00\uff0c\u6700\u540e\u4e00\u4e2a\u7d20\u6570\u540e\u9762\u6ca1\u6709\u7a7a\u683c)\uff0c\u5982\u679c\u6ca1\u6709\u5219\u8f93\u51fa-1\u3002\n\u6837\u4f8b\u8f93\u5165\uff1a\n100\n\u6837\u4f8b\u8f93\u51fa\uff1a\n11 31 41 61 71\n\n\u6211\u7684\u8bb0\u5f55(\u4f60\u53ef\u80fd\u770b\u4e0d\u61c2)\uff1a\n\n\t1. \u5404\u79cd\u9519\u8bef\u3002\u5224\u5b9a\u5230\u5e95\u662f\u4e0d\u662f\u7d20\u6570\uff0c\u8fd4\u56de\u7684\u4ee3\u8868\u4ec0\u4e48\u610f\u601d\u641e\u4e0d\u6e05\u695a\n\t2. \u521d\u59cb\u5316\u4e00\u5b9a\u8981\u7528for\u5faa\u73af\u4e00\u904d\n\t3. \u8d4b\u521d\u503c\u5230\u5e95\u5728\u54ea\u91cc\u8d4b\uff0c\u6bcf\u4e00\u6b21\u5faa\u73af\u5f00\u5934\n\t4. \u8f93\u51fa\u7684\u683c\u5f0f\uff0c\u8f93\u51fa\u4e3a-1\u4e4b\u540e\u6362\u884c\uff0c\u603b\u7684\u6700\u540e\u53c8\u6362\u884c\u51b2\u7a81\n\n\n\n\n\n<pre class=\"lang:default decode:true \" >#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;string.h&gt;\r\n#include&lt;math.h&gt;\r\nusing namespace std;\r\n#define MAX 10000\r\nint a[10002];\r\nbool judge(int x){  \/\/\u662f\u7d20\u6570\u5417\uff1f\r\n    if(x&lt;=1)\r\n        return false;\r\n    int bound=(int)sqrt((double)x)+1;\/\/\u591a\u52a0\u4e00\uff0c\u9632\u6b62\u5f3a\u8f6c\u5e26\u6765\u8bef\u5dee\r\n    for(int i=2;i&lt;bound;i++)\r\n        if(x%i==0)\r\n            return false;\r\n    return true;\r\n}\r\nvoid init(){\r\n    for(int i=0;i&lt;MAX;i++){\r\n        a[i]=0;\r\n    }\r\n    a[0]=1;\r\n    a[1]=1;\r\n    for(int i=2;i&lt;=MAX;i++){ \r\n        if(a[i]==1)\r\n            continue;\r\n        else{\r\n            if(!judge(i)){  \/\/\u4e0d\u662f\u7d20\u6570\r\n                a[i]=1;\r\n                for(int j=i*i;j&lt;=MAX;j+=i){  \/\/\u6240\u6709i\u7684\u500d\u6570\u6807\u8bb0\u4e3a1\r\n                    a[j]=1;\r\n                }\r\n            }\r\n            \/\/\u4e0d\u662f\u7d20\u6570\u5219\u4fdd\u6301\u521d\u59cb\u503c\uff0c\u4e3a0\r\n        }\r\n    }\r\n}\r\nint main(){\r\n    int n;\r\n    init();\r\n    bool isflag=false;\r\n    while(cin&gt;&gt;n){\r\n        isflag=false;\r\n        for(int i=2;i&lt;n;i++){\r\n            if(a[i]==0&amp;&amp;(i%10==1)){\r\n                if(isflag==false){\r\n                    cout&lt;&lt;i;\r\n                    isflag=true;\r\n                }\r\n                else\r\n                    cout&lt;&lt;&#8221; &#8220;&lt;&lt;i;\r\n            }\r\n        }\r\n        if(isflag==false)\r\n            cout&lt;&lt;&#8220;-1&#8221;;\r\n        cout&lt;&lt;endl;\r\n    }\r\n    return 0;\r\n}\r\n\/**************************************************************\r\n    Problem: 1163\r\n    User: WZDCJ0206\r\n    Language: C++\r\n    Result: Accepted\r\n    Time:10 ms\r\n    Memory:1568 kb\r\n****************************************************************\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u91cc\u5206\u4eab\u7684\u662f\u4e00\u4e9b\u6211\u505a\u8fc7\u76844\u661f\u3001\u4e94\u661f\uff0c\u4ee5\u53ca\u6211\u603b\u662f\u63d0\u4ea4\u8d85\u8fc73\u6b21\u7684\u9898\u76ee\u3002 \u9898\u76ee\u63cf\u8ff0\uff1a \u8f93\u5165\u4e00\u4e2a\u6574\u6570n(2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9Hs6X-1163","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":1,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/241\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}