∑ni=1∑mj=1gcd(i,j)
=∑nd=1d∗f(d)
=∑nd=1d∗∑d|jμ(j/d)∗F(d)
=∑i×j<=ni∗μ(j)∗F(i∗j)
=∑nT=1F(T)∗ϕ(T)
=∑nT=1[nT][mT]ϕ(T)
———-杜教筛:
已知问题:
S(n)=∑i=1nf(i)
取一个积性函数g使得f*g方便计算前缀和并做如下变换(g∗f)(i)=∑d|if(d)∗g(i/d)
∑i=1n(g∗f)(i)=∑i=1n∑d|if(d)∗g(i/d)
=∑i∗j<=nf(i)∗g(j)
=∑i=1ng(i)∑j=1n/if(j)
=∑i=1ng(i)∗S(n/i)
就可以得到
S(n)=1∗S(n)=g(1)∗S(n)
=∑i=1ng(i)∗S(n/i)−∑i=2ng(i)∗S(n/i)
=∑i=1n(g∗f)(i)−∑i=2ng(i)∗S(n/i)
后面就是递归计算了,注意要记忆化S