{"id":204584,"date":"2025-05-29T09:58:01","date_gmt":"2025-05-29T01:58:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204584\/"},"modified":"2025-05-29T09:58:01","modified_gmt":"2025-05-29T01:58:01","slug":"python-%e6%b1%82%e4%b8%a4%e6%95%b0%e9%97%b4%e7%b4%a0%e6%95%b0%e5%92%8c%e4%b8%ba%e4%bd%95%e4%bc%9a%e8%be%93%e5%87%ba%e7%ad%89%e4%ba%8e%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204584\/","title":{"rendered":"Python \u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55\u4f1a\u8f93\u51fa\u7b49\u4e8e\u53f7\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55\u4f1a\u8f93\u51fa\u7b49\u4e8e\u53f7\uff1f<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300aPython \u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55\u4f1a\u8f93\u51fa\u7b49\u4e8e\u53f7\uff1f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/1731294049673173612f2dc.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u7528python\u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55\u4f1a\u8f93\u51fa\u7b49\u4e8e\u53f7\uff1f<\/strong><\/p>\n<p>\u6b64\u95ee\u9898\u6e90\u81ea\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>def num(n):\n    for i in range(2,n):\n        if n %i == 0:\n            return 0\n        break\n    else:\n        return n\n\na = int(input())\nb = int(input())\ns = 0\nfor n in range(a,b+1):\n    s += num(n)\n    if n == 1:\n        print(\"he%d\"%s-1)\n    else:\n        print(\"he%d\"%s)<\/pre>\n<p>\u4ee3\u7801\u610f\u5728\u8ba1\u7b97\u7ed9\u5b9a\u533a\u95f4[a, b]\u5185\u6240\u6709\u7d20\u6570\u7684\u548c\u3002\u4f46\u8fd0\u884c\u7ed3\u679c\u5374\u662f\u8f93\u51fa\u4e86\u4e00\u5806\u7b49\u4e8e\u53f7\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u95ee\u9898\u51fa\u5728\u51fd\u6570num\u7684\u8fd4\u56de\u65b9\u5f0f\u3002\u8be5\u51fd\u6570\u65e8\u5728\u5224\u65ad\u7ed9\u5b9a\u6570\u5b57\u662f\u5426\u4e3a\u7d20\u6570\uff0c\u4f46\u6bcf\u6b21\u8c03\u7528\u53ea\u80fd\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u5982\u679c\u6570\u5b57\u662f\u7d20\u6570\uff0c\u5219\u8fd4\u56de\u6570\u5b57\u672c\u8eab\uff1b\u5426\u5219\uff0c\u8fd4\u56de0\u3002\u56e0\u6b64\uff0c\u5f53\u5728\u5faa\u73af\u4e2d\u7d2f\u52a0s\u65f6\uff0c\u53ea\u6709\u5f53\u7ed9\u5b9a\u6570\u5b57\u4e0d\u4e3a\u7d20\u6570\u65f6\u624d\u4f1a\u7d2f\u52a0\u3002<\/p>\n<p>\u6b63\u786e\u7684\u89e3\u51b3\u65b9\u6cd5\u662f\u5c06num\u51fd\u6570\u4fee\u6539\u4e3a\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u6240\u6709\u4e0d\u662f\u7ed9\u5b9a\u6570\u5b57\u56e0\u5b50\u7684\u503c\u3002\u7136\u540e\uff0c\u5728\u5faa\u73af\u4e2d\u5c06\u8fd9\u4e9b\u503c\u52a0\u5230s\u4e2d\uff1a<\/p>\n<pre>def num(n):\n    return [n if n%i!=0 else (n-n) for i in range(2,n)]\na = int(input())\nb = int(input())\ns = 0\nfor n in range(a,b+1):\n    for t in num(n):\n        s += t\n    if n == 1:\n        print(\"he%d\"%(s-1))\n    else:\n        print(\"he%d\"%s)<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPython \u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55\u4f1a\u8f93\u51fa\u7b49\u4e8e\u53f7\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u6c42\u4e24\u6570\u95f4\u7d20\u6570\u548c\u4e3a\u4f55&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204584","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204584"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204584\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}