{"id":598,"date":"2024-06-21T09:00:00","date_gmt":"2024-06-21T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=598"},"modified":"2024-06-25T16:55:53","modified_gmt":"2024-06-25T08:55:53","slug":"zerojudge-d120","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-d120\/","title":{"rendered":"ZeroJudge D120: Count the factors"},"content":{"rendered":"<h4 class=\"wp-block-heading\">UVa 10699 \u2013 Count the factors<\/h4>\n\n\n\n<p class=\"translation-block\">Write a program to calculate how many distinct prime factors a positive integer has. For example, 45 = 3<em>3<\/em>5, so 45 has 2 prime factors (3 and 5).<\/p>\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>Each set of test data is in a single line containing a positive integer N (1 &lt; N \u2264 1000000).<br>If N = 0, it means the input has ended.<\/td><td>For each set of test data, output a line indicating the number of distinct prime factors of N. Please refer to the sample output for the output format.<\/td><\/tr><tr><td>7<br>8<br>45<br>289384<br>930887<br>692778<br>636916<br>747794<br>238336<br>885387<br>760493<br>516650<br>641422<br>0<\/td><td>7 : 1<br>8 : 1<br>45 : 2<br>289384 : 3<br>930887 : 2<br>692778 : 5<br>636916 : 4<br>747794 : 3<br>238336 : 3<br>885387 : 2<br>760493 : 2<br>516650 : 3<br>641422 : 3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p>You can create a function to determine whether a number is prime. Use a for loop from 2 to N. If you find a factor of N, check if it's a prime number. If it's prime, increment the answer by 1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d120\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D120: Count the 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\nbool isPrime(int N) {\n    for (int i = 2; i&lt;int(sqrt(N)+1); i++) {\n        if (N % i == 0) return false;\n    }\n    return true;\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    while (cin &gt;&gt; N && N != 0) {\n        int ans = 0;\n        for (int i = 2; i&lt;=N; i++) {\n            if (N % i == 0 && isPrime(i)) {\n                ans++;\n            }\n        }\n        cout &lt;&lt; N &lt;&lt; &quot; : &quot; &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D120\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10699 &#8211; Count the factors \u5beb\u4e00\u500b\u7a0b\u5f0f\u7b97\u51fa\u4e00\u500b\u6b63\u6574\u6578\u6709\u591a\u5c11\u500b [&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":[18],"tags":[8,34,13,9],"class_list":["post-598","post","type-post","status-publish","format-standard","hentry","category-uva","tag-8","tag-34","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/598","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=598"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":991,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/598\/revisions\/991"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}