http://acm.hdu.edu.cn/showproblem.php?pid=6715
题意:
求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\),其中n,m是1e6范围内,10组。
不会,想了很久,也不知道假在哪里。大概是一开始方向就错了。
正解:
所求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\)
即:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i*j}{gcd(i,j)})\)
枚举g:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i*j}{g})*[gcd(i,j)==g]\)
由一个显然的事实:\(\mu(xy)=\mu(x)*\mu(y)*[gcd(x,y)==1]\)
代进去:\(\mu(\frac{i}{g}*j)=\mu(\frac{i}{g})*\mu(j)*[gcd(\frac{i}{g},j)==1]\) 后面那项显然为1
即:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i}{g})*\mu(j)*[gcd(\frac{i}{g},j)==1]*[gcd(i,j)==g]\)
同理:\(\mu(j)=\mu(\frac{j}{g}*g)=\mu(\frac{j}{g})*\mu(g)*[gcd(\frac{j}{g},g)==1]\)
即:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i}{g})*\mu(\frac{j}{g})*\mu(g)*[gcd(\frac{j}{g},g)==1]*[gcd(i,j)==g]\)
即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{n}\mu(\frac{i}{g})\sum\limits_{j=1}^{m}\mu(\frac{j}{g})*[gcd(\frac{j}{g},g)==1]*[gcd(i,j)==g]\)
即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[gcd(j,g)==1]*[gcd(i,j)==1]\)
即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[gcd(gcd(i,j),g)==1]\)
莫比乌斯反演:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)\sum\limits_{k|gcd(gcd(i,j),g)}\mu(k)\)
即:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[k|i]*[k|j]*[k|g]\)
一般是像上面那样变的,但是这里我们要把k放进去:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{\frac{N}{k}}\mu(gk)\sum\limits_{i=1}^{\frac{n}{gk}}\mu(ik)\sum\limits_{j=1}^{\frac{m}{gk}}\mu(jk)\)
为了简单,记:\(S(N,k)=\sum\limits_{i=1}^{\frac{N}{k}}\mu(ik)\)
那么上式就变成:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{\frac{N}{k}}\mu(gk)*S(\frac{n}{g},k)*S(\frac{m}{g},k)\)
那么枚举k,然后预处理S(N,k),再暴力算就可以了。
原文地址:https://www.cnblogs.com/Inko/p/11407474.html