本来考试遇到一个类似的,结果没动脑子直接上的杜教筛。。
g函数取\(\mu\)函数就行了,f就是约数个数函数(相当于\(1*1\)),套用杜教筛公式就好啦,但貌似\(\mu\)也要杜教筛..
注意\(\displaystyle \sum_{i=1}^{n}(f*g)(i)=\sum_{i=1}^{n}(1*1* \mu)(i)=\sum_{i=1}^{n}(1*e)(i)=n\)就可以啦
LL suan1(LL n)//mu
{
if(n<=M)return mu[n];
if(smu.count(n))return smu[n];
LL ans=1;
for(LL l=2,r;l<=n;l=r+1)r=n/(n/l),ans-=(r-l+1)*suan1(n/l);
return smu[n]=ans;
}
LL suan2(LL n)//d
{
if(n<=M)return d[n];
if(sd.count(n))return sd[n];
LL res=n;
for(LL l=2,r,las=1,now;l<=n;l=r+1)
{
r=n/(n/l);
now=suan1(r);
res-=(now-las)*suan2(n/l);
las=now;
}
return sd[n]=res;
}