题意:
求:
∑i=1n∑j=1nd(ij)
d 为约数个数和。
题解:
在这题我们知道一个公式。
所以是求:
=∑i=1n∑j=1n⌊ni⌋⌊nj⌋∑d|i,d|jμ(d)
=∑dnμ(d)(∑i=1⌊nd⌋⌊ndi⌋)2
然后分块+杜教筛?栋老师证出来是 O(n34)
不加hash记忆化好慢啊
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const LL mod=1000000007;
map <int,int> sum;
LL mu[10000010],prime[10000010],pr=0;
bool v[10000010];
void pre()
{
mu[1]=1;memset(v,true,sizeof(v));
for(LL i=2;i<=10000000;i++)
{
if(v[i]) prime[++pr]=i,mu[i]=-1;
for(LL j=1;j<=pr&&i*prime[j]<=10000000;j++)
{
v[i*prime[j]]=false;
if(i%prime[j]==0){mu[i*prime[j]]=0;break;}
mu[i*prime[j]]=-mu[i];
}
}
for(LL i=1;i<=10000000;i++) mu[i]=(mu[i-1]+mu[i])%mod;
}
LL solve(LL n)
{
if(n<=10000000) return mu[n];
if(sum[n]) return sum[n];
LL ans=1;LL j;
for(LL i=2;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans-solve(n/i)*(j-i+1))%mod;
}
sum[n]=ans;
return ans;
}
LL f(LL n)
{
LL j,ans=0;
for(LL i=1;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans+(n/i)*(j-i+1)%mod)%mod;
}
return ans*ans%mod;
}
LL n;
int main()
{
scanf("%lld",&n);
pre();
LL j,ans=0;
for(LL i=1;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans+(solve(j)-solve(i-1))*f(n/i)%mod)%mod;
}
printf("%lld",(ans+mod)%mod);
}