{"id":2311,"date":"2024-11-24T11:53:45","date_gmt":"2024-11-24T03:53:45","guid":{"rendered":"https:\/\/airy.cn\/WordPress\/?p=2311"},"modified":"2025-09-09T14:55:14","modified_gmt":"2025-09-09T06:55:14","slug":"%e8%b4%a8%e6%95%b0-%e7%b4%a0%e6%95%b0","status":"publish","type":"post","link":"https:\/\/airy.cn\/WordPress\/?p=2311","title":{"rendered":"\u6570\u5b66: \u8d28(\u7d20)\u6570 \/ \u8d28\u56e0\u6570\u5206\u89e3"},"content":{"rendered":"\n<p>\u8d28\u6570(prime number)\u53c8\u79f0\u7d20\u6570\uff0c\u6709\u65e0\u9650\u4e2a\u3002\u4e00\u4e2a\u5927\u4e8e 1 \u7684\u81ea\u7136\u6570\uff0c\u9664\u4e86 1 \u548c\u5b83\u672c\u8eab\u5916\uff0c\u4e0d\u80fd\u88ab\u5176\u4ed6\u81ea\u7136\u6570\u6574\u9664\uff0c\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f\u8be5\u6570\u9664\u4e86 1 \u548c\u5b83\u672c\u8eab\u4ee5\u5916\u4e0d\u518d\u6709\u5176\u4ed6\u7684\u56e0\u6570\uff1b\u5426\u5219\u79f0\u4e3a\u5408\u6570\u3002<\/p>\n\n\n\n<p>\u8d28(\u7d20)\u6570\u68c0\u6d4b\u5668(100\u4e07\u4ee5\u5185\u5e76\u8ba1\u7b97\u51fa\u8d28\u56e0\u6570) <a href=\"https:\/\/airy.cn\/learn\/CheckPrime.php\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/airy.cn\/learn\/CheckPrime.php <\/a><\/p>\n\n\n\n<p>\u8d28(\u7d20)\u6570\u68c0\u6d4b\u5668 \u8d85\u5927\u6570 \u6b63\u6574\u6570  <a href=\"https:\/\/airy.cn\/learn\/CheckPrime2.php\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/airy.cn\/learn\/CheckPrime2.php <\/a><\/p>\n\n\n\n<p>\u8d28\u56e0\u6570\u5206\u89e3\u5de5\u5177(\u542b\u6b65\u9aa4\u8fc7\u7a0b) <a href=\"https:\/\/airy.cn\/learn\/factorize.php\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/airy.cn\/learn\/factorize.php<\/a><\/p>\n\n\n\n<p><strong>\u8d28\u56e0\u6570\u5206\u89e3\u8fc7\u7a0b<\/strong><\/p>\n\n\n\n<p>\u8d28\u56e0\u6570\u5206\u89e3\u662f\u5c06\u4e00\u4e2a\u6574\u6570\u8868\u793a\u4e3a\u8d28\u6570\u7684\u4e58\u79ef\u7684\u8fc7\u7a0b\u3002\u8d28\u6570\u662f\u6307\u53ea\u80fd\u88ab1\u548c\u81ea\u8eab\u6574\u9664\u7684\u81ea\u7136\u6570\uff08\u4f8b\u5982\uff1a2\u30013\u30015\u30017\u300111\u7b49\uff09\u3002\u8d28\u56e0\u6570\u5206\u89e3\u7684\u4e3b\u8981\u76ee\u6807\u662f\u627e\u5230\u4e00\u4e2a\u6570\u7684\u6240\u6709\u8d28\u56e0\u6570\u4ee5\u53ca\u5b83\u4eec\u7684\u5bf9\u5e94\u6307\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8d28\u56e0\u6570\u5206\u89e3\u7684\u6b65\u9aa4<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u8fdb\u884c\u8d28\u56e0\u6570\u5206\u89e3\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9009\u62e9\u8981\u5206\u89e3\u7684\u6574\u6570&nbsp;n<\/strong>\uff1a\u786e\u5b9a\u4f60\u60f3\u8fdb\u884c\u8d28\u56e0\u6570\u5206\u89e3\u7684\u6570\u3002<\/li>\n\n\n\n<li><strong>\u4ece\u6700\u5c0f\u8d28\u6570\u5f00\u59cb\u5c1d\u8bd5<\/strong>\uff1a\u8d28\u6570\u4ece 2 \u5f00\u59cb\uff0c\u5c1d\u8bd5\u7528\u8d28\u6570\u9010\u6e10\u53bb\u9664&nbsp;n\u3002<\/li>\n\n\n\n<li><strong>\u9664\u6cd5\u6d4b\u8bd5<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u7528\u5f53\u524d\u8d28\u6570&nbsp;p&nbsp;\u9664\u4ee5&nbsp;n\u3002<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;n \u53ef\u4ee5\u88ab&nbsp;p\u6574\u9664\uff0c\u5219\u5c06\u8d28\u6570&nbsp;p&nbsp;\u8bb0\u5f55\uff0c\u5e76\u5c06&nbsp;n&nbsp;\u9664\u4ee5&nbsp;p\uff0c\u7ee7\u7eed\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230&nbsp;n&nbsp;\u4e0d\u80fd\u518d\u88ab&nbsp;p&nbsp;\u6574\u9664\u3002<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;n \u4e0d\u80fd\u88ab&nbsp;p&nbsp;\u6574\u9664\uff0c\u5219\u5c1d\u8bd5\u4e0b\u4e00\u4e2a\u8d28\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u91cd\u590d\u4ee5\u4e0a\u8fc7\u7a0b<\/strong>\uff1a\u91cd\u590d\u6b65\u9aa4 3\uff0c\u76f4\u5230&nbsp;n&nbsp;\u9664\u81f3 1 \u4e3a\u6b62\u3002\u8bb0\u5f55\u6240\u6709\u7684\u8d28\u56e0\u6570\u53ca\u5176\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\u7ed3\u679c<\/strong>\uff1a\u5f53&nbsp;n&nbsp;\u4e3a 1 \u65f6\uff0c\u8d28\u56e0\u6570\u5206\u89e3\u5b8c\u6210\uff0c\u7ed3\u679c\u53ef\u4ee5\u4ee5\u8d28\u6570\u53ca\u5176\u6307\u6570\u7684\u5f62\u5f0f\u8f93\u51fa\u3002<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"786\" src=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-17.png\" alt=\"\" class=\"wp-image-2326\" srcset=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-17.png 553w, https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-17-211x300.png 211w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"585\" src=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-21.png\" alt=\"\" class=\"wp-image-2332\" srcset=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-21.png 709w, https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-21-300x248.png 300w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8d28\u6570\u6c42\u89e3\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"427\" src=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-18.png\" alt=\"\" class=\"wp-image-2328\" srcset=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-18.png 723w, https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-18-300x177.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"422\" src=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-19.png\" alt=\"\" class=\"wp-image-2330\" srcset=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-19.png 600w, https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-19-300x211.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"474\" src=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-20.png\" alt=\"\" class=\"wp-image-2331\" srcset=\"https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-20.png 722w, https:\/\/airy.cn\/WordPress\/wp-content\/uploads\/2024\/11\/image-20-300x197.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/figure>\n\n\n\n<p>VBScript\u4ee3\u7801\u6765\u9a8c\u8bc1\u67d0\u4e9b\u6570\u5b57\u662f\u5426\u662f\u7d20\u6570\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u4f1a\u63d0\u793a\u7528\u6237\u8f93\u5165\u4e00\u4e2a1\u52301,000,000,000\u4e4b\u95f4\u7684\u6570\u5b57\uff0c\u5e76\u68c0\u67e5\u8fd9\u4e2a\u6570\u5b57\u662f\u5426\u4e3a\u7d20\u6570\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>vbscript<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Option Explicit  \n\nDim num, isPrime  \n\n' \u8f93\u5165\u6570\u5b57  \nnum = InputBox(\"\u8bf7\u8f93\u5165\u8981\u9a8c\u8bc1\u7684\u6570\u5b57\uff08\u8303\u56f4: 1 \u5230 1,000,000,000\uff09:\")  \n\n' \u9a8c\u8bc1\u8f93\u5165\u662f\u5426\u4e3a\u6709\u6548\u6570\u5b57\u53ca\u8303\u56f4  \nIf IsNumeric(num) Then  \n    num = CDbl(num) ' \u4f7f\u7528 CDbl \u8fdb\u884c\u8f6c\u6362\uff0c\u4ee5\u652f\u6301\u66f4\u5927\u7684\u6570\u5b57  \n    \n    ' \u68c0\u67e5\u6570\u5b57\u8303\u56f4  \n    If num &lt; 1 Or num &gt; 1000000000 Then  \n        MsgBox \"\u6570\u5b57\u5fc5\u987b\u5728 1 \u5230 1,000,000,000 \u4e4b\u95f4\u3002\"  \n    Else  \n        isPrime = True  \n\n        ' \u5c0f\u4e8e2\u7684\u6570\u5b57\u4e0d\u662f\u7d20\u6570  \n        If num &lt; 2 Then  \n            isPrime = False  \n        Else  \n            ' \u68c0\u67e5\u662f\u5426\u4e3a\u7d20\u6570  \n            Dim i  \n            For i = 2 To Int(Sqr(num))  \n                If (num Mod i) = 0 Then  \n                    isPrime = False  \n                    Exit For  \n                End If  \n            Next  \n        End If  \n\n        ' \u8f93\u51fa\u7ed3\u679c  \n        If isPrime Then  \n            MsgBox num &amp; \" \u662f\u7d20\u6570.\"  \n        Else  \n            MsgBox num &amp; \" \u4e0d\u662f\u7d20\u6570.\"  \n        End If  \n    End If  \nElse  \n    MsgBox \"\u8bf7\u8f93\u5165\u4e00\u4e2a\u6709\u6548\u7684\u6570\u5b57.\"  \nEnd If<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u4f7f\u7528\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6253\u5f00\u8bb0\u4e8b\u672c\u6216\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u3002<\/li>\n\n\n\n<li>\u590d\u5236\u4e0a\u9762\u7684\u4ee3\u7801\u5e76\u7c98\u8d34\u5230\u7f16\u8f91\u5668\u4e2d\u3002<\/li>\n\n\n\n<li>\u5c06\u6587\u4ef6\u4fdd\u5b58\u4e3a<code>CheckPrime.vbs<\/code>\uff08\u786e\u4fdd\u9009\u62e9\u201c\u6240\u6709\u6587\u4ef6\u201d\u4f5c\u4e3a\u4fdd\u5b58\u7c7b\u578b\uff09\u3002<\/li>\n\n\n\n<li>\u53cc\u51fb\u4fdd\u5b58\u7684\u6587\u4ef6\u8fd0\u884c\u7a0b\u5e8f\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u4e00\u4e2a\u6570\u5b57\uff0c\u7a0b\u5e8f\u4f1a\u544a\u8bc9\u4f60\u8fd9\u4e2a\u6570\u5b57\u662f\u5426\u662f\u7d20\u6570\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u8bf4\u660e\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u7a0b\u5e8f\u4f7f\u7528\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u7b97\u6cd5\uff0c\u901a\u8fc7\u68c0\u67e5\u4ece2\u5230\u8f93\u5165\u6570\u5b57\u5e73\u65b9\u6839\u7684\u6240\u6709\u6574\u6570\uff0c\u4ee5\u67e5\u770b\u662f\u5426\u80fd\u6574\u9664\u8be5\u6570\u5b57\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6570\u5b57\u5c0f\u4e8e2\uff0c\u5219\u76f4\u63a5\u8ba4\u4e3a\u4e0d\u662f\u7d20\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>2025-09-09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8d28\u6570(prime number)\u53c8\u79f0\u7d20\u6570\uff0c\u6709\u65e0\u9650\u4e2a\u3002\u4e00\u4e2a\u5927\u4e8e 1 \u7684\u81ea\u7136\u6570\uff0c\u9664\u4e86 1 \u548c\u5b83\u672c\u8eab\u5916\uff0c\u4e0d\u80fd\u88ab\u5176\u4ed6\u81ea &#8230; <a title=\"\u6570\u5b66: \u8d28(\u7d20)\u6570 \/ \u8d28\u56e0\u6570\u5206\u89e3\" class=\"read-more\" href=\"https:\/\/airy.cn\/WordPress\/?p=2311\" aria-label=\"\u9605\u8bfb \u6570\u5b66: \u8d28(\u7d20)\u6570 \/ \u8d28\u56e0\u6570\u5206\u89e3\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_kadence_starter_templates_imported_post":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-2311","post","type-post","status-publish","format-standard","hentry","category-13"],"_links":{"self":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/2311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2311"}],"version-history":[{"count":12,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/2311\/revisions"}],"predecessor-version":[{"id":2559,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=\/wp\/v2\/posts\/2311\/revisions\/2559"}],"wp:attachment":[{"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/airy.cn\/WordPress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}