{"id":3422,"date":"2025-03-21T05:09:37","date_gmt":"2025-03-20T21:09:37","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=3422"},"modified":"2025-03-21T05:09:37","modified_gmt":"2025-03-20T21:09:37","slug":"uoj-188-%e3%80%90ur-13%e3%80%91sanrd","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/uoj-188-%e3%80%90ur-13%e3%80%91sanrd\/","title":{"rendered":"UOJ #188. \u3010UR #13\u3011Sanrd"},"content":{"rendered":"<p>\u9898\u610f\uff1a\u6b21\u5c0f\u7d20\u56e0\u5b50\u524d\u7f00\u548c\u3002<\/p>\n<p>\u7c7b\u4f3c <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/project-euler-521-smallest-prime-factor\/\">PE 521 \u6c42\u6700\u5c0f\u7d20\u56e0\u5b50\u524d\u7f00\u548c<\/a>\uff0c\u867d\u7136\u4e0d\u662f\u79ef\u6027\u51fd\u6570\uff0c\u4f46\u4e0d\u59a8\u788d\u6211\u4eec\u7b5b\u3002<\/p>\n<p>\u4ee4 S(n, k) \u8868\u793a\u6b21\u5c0f\u8d28\u56e0\u5b50 >= P[k] \u65f6\u7684\u524d\u7f00\u548c\uff08P[0] = 0)\u3002<br \/>\n\u8f6c\u79fb\uff0c\u5206\u4e24\u79cd\u60c5\u51b5\uff1a<br \/>\n1. \u5269\u4f59\u90e8\u5206\u662f\u4e00\u4e2a\u66f4\u5927\u7684\u7d20\u6570\uff0c\u8d21\u732e\u662f\uff0cp * (g[id(n)] &#8211; g[p])\u3002<br \/>\n2. \u679a\u4e3e\u6700\u5c0f\u56e0\u5b50\u5206\u89e3\uff0c\u9012\u5f52\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\n#include &lt;lastweapon\/io&gt;\nusing namespace std;\n\nconst int N = int(1e6) + 9;\nLL n; int nn; int P&#x5B;N], Pn;\nLL di&#x5B;N], g&#x5B;N]; int dn;\ninline int id(LL x) {return x &lt;= nn ? x : dn-n\/x+1;}\n\nLL S(LL n, int k) {\n    int p = P&#x5B;k]; if (n &lt;= p) return 0;\n    LL z = p * (g&#x5B;id(n)] - g&#x5B;p]);\n    FOR_1(i, k+1, Pn) {\n        LL p = P&#x5B;i]; if (p*p &gt; n) break;\n        for (LL j=n\/p;j&gt;=p;j\/=p) {\n            z += S(j, i) + p;\n        }\n    }\n    return z;\n}\n\nLL S(LL n) {\n    ::n = n; nn = sqrt(n); Pn = dn = 0;\n    for (LL i=1,j;i&lt;=n;i=j+1) {\n        di&#x5B;++dn] = j = n\/(n\/i);\n        g&#x5B;dn] = j-1;\n    }\n    FOR_1(p, 2, nn) if (g&#x5B;p] != g&#x5B;p-1]) {\n        P&#x5B;++Pn] = p; for (LL i=dn,ii=di&#x5B;i];(LL)p*p&lt;=ii;ii=di&#x5B;--i]) {\n            g&#x5B;i] -= g&#x5B;id(ii\/p)] - g&#x5B;p-1];\n        }\n    }\n    if (!Pn) return 0;\n    return S(n, 0);\n}\n\nint main(){\n    LL l, r; RD(l, r);\n    cout &lt;&lt; S(r) - S(l-1) &lt;&lt; endl;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f\uff1a\u6b21\u5c0f\u7d20\u56e0\u5b50\u524d\u7f00\u548c\u3002 \u7c7b\u4f3c PE 521 \u6c42\u6700\u5c0f\u7d20\u56e0\u5b50\u524d\u7f00\u548c\uff0c\u867d\u7136\u4e0d\u662f\u79ef\u6027\u51fd\u6570\uff0c\u4f46\u4e0d\u59a8\u788d\u6211\u4eec\u7b5b\u3002 \u4ee4 S(n, k) \u8868\u793a\u6b21\u5c0f\u8d28\u56e0\u5b50 >= P[k] \u65f6\u7684\u524d\u7f00\u548c\uff08P[0] = 0)\u3002 \u8f6c\u79fb\uff0c\u5206\u4e24\u79cd\u60c5\u51b5\uff1a 1. \u5269\u4f59\u90e8\u5206\u662f\u4e00\u4e2a\u66f4\u5927\u7684\u7d20\u6570\uff0c\u8d21\u732e\u662f\uff0cp * (g[id(n)] &#8211; g[p])\u3002 2. \u679a\u4e3e\u6700\u5c0f\u56e0\u5b50\u5206\u89e3\uff0c\u9012\u5f52\u3002 #include &lt;lastweapon\/io&gt; using namespace std; const int N = int(1e6) + 9; LL n; int nn; int P&#x5B;N], Pn; LL di&#x5B;N], g&#x5B;N]; int dn; inline int id(LL x) {return x &lt;= nn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-3422","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-Tc","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=3422"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3422\/revisions"}],"predecessor-version":[{"id":3423,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/3422\/revisions\/3423"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=3422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=3422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=3422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}