{"id":564,"date":"2024-06-10T09:00:00","date_gmt":"2024-06-10T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=564"},"modified":"2024-05-10T23:51:32","modified_gmt":"2024-05-10T15:51:32","slug":"zerojudge-n362","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-n362\/","title":{"rendered":"ZeroJudge B362: Primes"},"content":{"rendered":"<p class=\"translation-block\">Ah-Xuan is a junior high school teacher who has recently taught the unit on prime factorization. To help students practice, he will present a number N and ask the students to answer whether this number is a product of two prime numbers. If it is, they should also state which two prime numbers multiply to give this number.<\/p>\n\n\n\n<p class=\"\">Please write a program to generate the correct answer.<\/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>The input consists of only one line containing a number N<sup>9<\/sup>).<\/td><td class=\"translation-block\">If N is the product of two prime numbers A and B (where A \u2264 B), output the two prime numbers A and B separated by a single space. If N is not the product of two prime numbers, output \"0 0\".<\/td><\/tr><tr><td>14<\/td><td>2 7<\/td><\/tr><tr><td>63<\/td><td>0 0<\/td><\/tr><tr><td>917747<\/td><td>257 3571<\/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\">To determine the factors of N, you only need to iterate from 2 to sqrt(N) + 1 using a for loop. If there is a factor, check if it's a prime number by verifying if there are any factors between 2 and sqrt(factor) + 1. Also, check if N divided by the factor is a prime number. If it is, you can output the two numbers and break the loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=n362\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B362: Primes<\/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{\n    for (int i = 2; i&lt;int(sqrt(N))+1; i++)\n    {\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    cin &gt;&gt; N;\n    bool ok = false;\n    for (int i = 2; i&lt;int(sqrt(N))+1; i++)\n    {\n        if (N % i == 0 && isPrime(i) && isPrime(N \/ i))\n        {\n            ok = true;\n            cout &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; N\/i &lt;&lt; &quot;\\n&quot;;\n            break;\n        }\n    }\n    if (!ok) cout &lt;&lt; &quot;0 0\\n&quot;;\n}\n\n\/\/ZeroJudge N362\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u963f\u8ed2\u662f\u500b\u570b\u4e2d\u8001\u5e2b\uff0c\u4ed6\u6700\u8fd1\u525b\u6559\u5230\u8cea\u56e0\u6578\u5206\u89e3\u9019\u500b\u55ae\u5143\uff0c\u70ba\u4e86\u8b93\u5b78\u751f\u5011\u7df4\u7fd2\uff0c\u4ed6\u6703\u63d0\u51fa\u4e00\u500b\u6578\u5b57 N\uff0c\u8acb\u540c\u5b78\u56de\u7b54\u9019\u500b\u6578\u5b57\u662f [&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":[25],"tags":[8,34,13,9],"class_list":["post-564","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-8","tag-34","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/564","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=564"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":565,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/564\/revisions\/565"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}