{"id":595,"date":"2019-02-10T00:28:29","date_gmt":"2019-02-09T16:28:29","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=595"},"modified":"2019-02-10T13:07:45","modified_gmt":"2019-02-10T05:07:45","slug":"lp2257-yy%e7%9a%84gcd","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2019\/02\/10\/lp2257-yy%e7%9a%84gcd\/","title":{"rendered":"lp2257 YY\u7684GCD"},"content":{"rendered":"\n<p>\u4e0d\u59a8\u8bbe\\(n&lt;m\\)<br> \u9996\u5148\u5c06\u539f\u63d0\u95ee\u5f62\u5f0f\u5316\uff0c\u53ef\u4ee5\u5f97\u5230\u539f\u5f0f\u4e3a\uff1a<br> $$\\sum_{x=1}^{n}\\sum_{y=1}^{m}\\sum_{p\\in P}[gcd(x,y)==p] $$<br> \u5c06\u6240\u6709\u7684\\(x,y\\)\u90fd\u9664\u4ee5\\(gcd(x,y)\\)\uff0c\u5219\u539f\u5f0f\u53ef\u8f6c\u5316\u4e3a\uff1a<br> $$\\sum_{x=1}^{\\lfloor \\frac{n}{p} \\rfloor}\\sum_{y=1}^{\\lfloor \\frac{m}{p} \\rfloor}\\sum_{p\\in P}[gcd(x,y)==1]$$<br> \u7136\u540e\uff0c\u6839\u636e\u83ab\u6bd4\u4e4c\u65af\u51fd\u6570\u7684\u57fa\u672c\u6027\u8d28\uff0c\u6211\u4eec\u6709\uff1a<br> $$\\sum_{d|n}\\mu(d)=[n==1]$$<br> \u66ff\u6362\u5165\u539f\u5f0f\u53ef\u4ee5\u5f97\u5230\uff1a<br> $$\\sum_{x=1}^{\\lfloor \\frac{n}{p} \\rfloor}\\sum_{y=1}^{\\lfloor \\frac{m}{p} \\rfloor}\\sum_{p\\in P}\\sum_{d|gcd(x,y)}\\mu(d)$$<br> \u5c06\\(d|gcd(x,y)\\)\u4e00\u5f0f\u5316\u7b80\u53ef\u5f97\uff1a<br> $$d|gcd(x,y)=d|x\\&amp;\\&amp;d|y$$<br> \u4ee3\u5165\u539f\u5f0f\uff1a<br> $$\\sum_{x=1}^{\\lfloor \\frac{n}{p} \\rfloor}\\sum_{y=1}^{\\lfloor \\frac{m}{p} \\rfloor}\\sum_{p\\in P}\\sum_{d|x\\&amp;\\&amp;d|y}\\mu(d)$$<br> \u5c06\u6240\u6709\u7684\\(x,y\\)\u90fd\u9664\u4ee5\\(d\\)\uff0c\u5219\u539f\u5f0f\u53ef\u8f6c\u5316\u4e3a\uff1a<br> $$\\sum_{x=1}^{\\lfloor \\frac{n}{pd} \\rfloor}\\sum_{y=1}^{\\lfloor \\frac{m}{pd} \\rfloor}\\sum_{p\\in P}\\mu(d)$$<br> \u7531\u4e8e\\(x,y\\)\u5bf9\u540e\u534a\u90e8\u5206\u5f0f\u5b50\u65e0\u5f71\u54cd\uff0c\u4e14\\(pd\\le n\\)\u539f\u5f0f\u53ef\u53d8\u5f0f\u4e3a\uff1a<br> $$\\sum_{p\\in P}\\sum_{d=1}^{\\lfloor \\frac{n}{p} \\rfloor}\\mu(d)\\lfloor \\frac{n}{pd} \\rfloor \\lfloor \\frac{m}{pd} \\rfloor$$<br> \u4e3a\u4e86\u51cf\u5c11\u679a\u4e3e\u7684\u6570\u91cf\uff0c\u4e0d\u59a8\u8bbe\\(q=pd\\)\uff0c\u90a3\u4e48\u6211\u4eec\u53c8\u53ef\u4ee5\u5c06\u539f\u5f0f\u8f6c\u5316\u4e3a\uff1a<br> $$\\sum_{q=1}^{n}\\lfloor \\frac{n}{q} \\rfloor \\lfloor \\frac{m}{q} \\rfloor \\sum_{p\\in P\\&amp;\\&amp;pd==q}\\mu(d)$$<br> \u53c8\uff0c\u6839\u636e\u72c4\u5229\u514b\u96f7\u5377\u79ef\u7684\u57fa\u672c\u5f0f<br> $$g=f u  \\Rightarrow  g(x)=\\sum_{a b=x} f(a) u(b)$$ <br>\u6211\u4eec\u53d1\u73b0\uff0c\u4e0a\u5f0f\u9760\u53f3\u7684\u5982\u4e0b\u90e8\u5206\u53ef\u4ee5\u4f5c\u51fa\u53d8\u6362\uff1a<br>$$\\sum_{p\\in P\\&amp;\\&amp;pd==q}\\mu(d)=g(q)=\\sum_{pd=q}[p\\in P]\\mu(d)$$<br>\u82e5\u4ee4\uff1a<br>$$f(p)=[p\\in P]$$ <br>\u5219\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff1a <br>$$ g(q)=f(p)&nbsp;\\mu(d)$$<br> \u6545\u800c\u8fd9\u4e00\u90e8\u5206\u7684\u503c\u53ef\u4ee5\u7528\u72c4\u5229\u514b\u96f7\u5377\u79ef\u6765\\(O(nln_n)\\)\u9884\u5904\u7406\u3002<br> \u4e00\u770b\u6570\u636e\u8303\u56f4\uff0c\u5b8c\u4e86\uff1a\\(10^7\\)\uff0c\\(O(nln_n)\\)\u7684\u590d\u6742\u5ea6\u663e\u7136\u662f\u4e0d\u591f\u4f18\u79c0\u7684\u3002\u6211\u4eec\u9700\u8981\u5c06\u5b83\u4f18\u5316\u5230\\(O(n)\\)<\/p>\n\n\n\n<p>\u6211\u4eec\u8003\u8651\u5bf9\u8fd9\u4e2a\u51fd\u6570\\(g\\)\u8fdb\u884c\u7ebf\u6027\u7b5b\u3002<br>\n\u6211\u4eec\u53d1\u73b0\uff0c\u4e0a\u5f0f\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u53d8\u6362\uff1a<br>\n$$g(q)=\\sum_{pd=q\\&amp;\\&amp;p\\in P}\\mu(d)=\\sum_{p\\in P\\&amp;\\&amp;p|q}\\mu(\\frac{q}{p})$$<br>\n\u672c\u8d28\u4e0a\u5c31\u662f\u679a\u4e3e\u5176\u8d28\u56e0\u5b50\u4e4b\u548c\u5e76\u6c42\u5176\u9664\u4ee5\u8be5\u8d28\u56e0\u5b50\u7684\u83ab\u6bd4\u4e4c\u65af\u51fd\u6570\u503c\u4e4b\u548c\u3002<br>\n\u6211\u4eec\u5206\u4e09\u7c7b\u8ba8\u8bba\u3002<br>\n\u5bf9\u4e8e\\(g(x)\\)<br>\n\u5982\u679c\\(x\\in P\\)\uff0c\u663e\u7136\\(g(x)=\\mu(1)=1\\)<br>\n\u5982\u679c\\(x=a^vb,a\\in P,v&gt;1\\)\uff0c\u5219\u663e\u7136\u679a\u4e3e\u5176\u4ed6\u7684\u8d28\u6570\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\\(g(x)=\\mu(b)\\)<br>\n\u5982\u679c\\(x=ab,a\\in P\\)\uff0c\u5219\uff0c\\(g(x)\\)\u7684\u503c\uff0c\u7b49\u4ef7\u4e8e\u5728\u8ba1\u7b97\\(g(b)\\)\u7684\u548c\u7684\u65f6\u5019\u6bcf\u4e00\u6b21\u8ba1\u7b97\u90fd\u591a\u4e58\u4e0a\u4e00\u4e2a\\(a\\)\u7684\u8d21\u732e\uff0c\u4e5f\u5c31\u662f\u4e58\u4e0a\u8d1f\u4e00\u3002\u7136\u540e\u5c06\u8fd9\u4e2a\u503c\u518d\u52a0\u4e0a\u679a\u4e3e\\(a\\)\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662f\\(\\mu(b)\\)\uff0c\u5373\\(g(x)=-g(b)+\\mu(b)\\)<br>\n\u7136\u540e\u5927\u529b\u4e0a\u4e00\u4e2a\u7ebf\u6027\u7b5b\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5de6\u534a\u90e8\u5206\uff0c\u4e0a\u4e00\u4e2a\u6570\u8bba\u5206\u5757\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstdio>\n\nconst int N = 10000000+5;\n\nint p[N\/10],g[N],mu[N],n,m;\nbool ip[N];\nvoid prpr(){\n\tp[0]=0;mu[1]=1;ip[1]=1;\n\tfor(int i=2;i&lt;=10000000;++i){\n\t\tif(!ip[i]){\n\t\t\tp[++p[0]]=i;\n\t\t\tmu[i]=-1;\n\t\t\tg[i]=1;\n\t\t}\n\t\tfor(int j=1;j&lt;=p[0]&amp;&amp;p[j]*i&lt;=10000000;++j){\n\t\t\tip[i*p[j]]=1;\n\t\t\tif(!(i%p[j])){\n\t\t\t\tg[i*p[j]]=mu[i];\n\t\t\t\tmu[i*p[j]]=0;\n\t\t\t\tbreak;\n\t\t\t}else{\n\t\t\t\tmu[i*p[j]]=-mu[i];\n\t\t\t\tg[i*p[j]]=-g[i]+mu[i];\n\t\t\t}\n\t\t}\n\t}\n\tfor(int i=2;i&lt;=10000000;++i){\n\t\tg[i]+=g[i-1]; \n\t}\n}\nlong long ans;\nvoid init(){\n\tscanf(\"%d%d\",&amp;n,&amp;m);\n\tn>m?n^=m^=n^=m:0;\n\tans=0;\n\tint k=0;\n\tfor(int i=1;i&lt;=n;i=k+1){\n\t\tk=std::min(n\/(n\/i),m\/(m\/i));\n\t\tans+=1ll*(n\/i)*(m\/i)*(g[k]-g[i-1]);\n\t}\n\tprintf(\"%lld\\n\",ans);\n}\n\nint main(){\n\tprpr();\n\tint T;\n\tscanf(\"%d\",&amp;T);\n\twhile(T--){\n\t\tinit();\n\t}\n\treturn 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u59a8\u8bbe\\(n&lt;m\\) \u9996\u5148\u5c06\u539f\u63d0\u95ee\u5f62\u5f0f\u5316\uff0c\u53ef\u4ee5\u5f97\u5230\u539f\u5f0f\u4e3a\uff1a $$\\sum_{x=1}^{n}\\sum_{ &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2019\/02\/10\/lp2257-yy%e7%9a%84gcd\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp2257 YY\u7684GCD\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,27,60,82,6,83],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/595"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=595"}],"version-history":[{"count":10,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":605,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/595\/revisions\/605"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}