{"id":229,"date":"2024-04-26T21:23:56","date_gmt":"2024-04-26T13:23:56","guid":{"rendered":"https:\/\/seanxd.com\/?p=229"},"modified":"2024-04-26T21:23:58","modified_gmt":"2024-04-26T13:23:58","slug":"zerojudge-a740","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a740\/","title":{"rendered":"ZeroJudge A740: Sum of Prime Factors"},"content":{"rendered":"<p class=\"translation-block\">Find the sum of all prime factors of a number (<strong>1 is not considered a prime number<\/strong>).<\/p>\n\n\n\n<p class=\"\">For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"\">6 = 2 * 3, so the output is 2 + 3 = 5<\/li>\n\n\n\n<li class=\"\">8 = 2 * 2 * 2, so the output is 2 + 2 + 2 = 6<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td class=\"translation-block\">One positive integer per line, with x &lt; 2000000000, until <strong>EOF<\/strong>.<\/td><td>The corresponding sum of prime factors.<\/td><\/tr><tr><td>19<br>32<\/td><td>19<br>10<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"translation-block\">Using a <strong>For loop<\/strong> to determine how many prime numbers there are in the input integers <strong>(only need to check up to the square root of the input data)<\/strong>, and it is recommended to use <strong>cin for optimization<\/strong>. According to the test data, <strong>1 is not considered a prime number<\/strong>, so if the input data is a prime number, simply output that prime number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a740\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A740: Sum of Prime Factors<\/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;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(nullptr);\n    int num;\n    while (cin &gt;&gt; num)\n    {\n        int ans = 0, OG = num;\n        for (int i = 2; i &lt;= (sqrt(OG))+1; i++)\n        {\n            if (num % i == 0)\n            {\n                while (num % i == 0 && num &gt; 1)\n                {\n                    ans += i;\n                    num \/= i;\n                }\n            }\n        }\n        if (num != 1) ans += num;\n        cout &lt;&lt; ans &lt;&lt; endl;\n    }\n}\n\n\/\/ZeroJudge A740\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6c42\u4e00\u500b\u6578\u5168\u90e8\u8cea\u56e0\u6578\u4e4b\u548c (1 \u4e0d\u7b97\u8cea\u6578)\u3002 \u6bd4\u5982\uff1a \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38\u5165 \u7bc4\u4f8b\u8f38\u51fa \u6bcf\u884c\u4e00\u500b\u6b63\u6574\u6578\uff0cx &lt; [&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":[6],"tags":[8,13,9],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-6","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/229\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}