题意:
求:
∑in∑jnd(ij)
题解:
首先有这个东西:
nm
的因子是
∑p|n∑q|mnpq[(p,q)=1]
所以要求
∑in∑jn∑p|i∑q|jnpq[(p,q)=1]
然后上反演。
∑dnμ(d)d∑p⌊nd⌋sum(⌊npd⌋)∑q⌊nd⌋q⌊ndq⌋
挺好推的不写过程了。
然后杜教筛 ∑ndμ(d)d
code:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
const LL mod=1000000007;
using namespace std;
LL mu[1000010],prime[1000010],pr=0,n;
bool v[1000010];
LL Sum[100010];
void pre()
{
mu[1]=1;memset(v,true,sizeof(v));
for(LL i=2;i<=1000000;i++)
{
if(v[i]) prime[++pr]=i,mu[i]=-1;
for(LL j=1;j<=pr&&i*prime[j]<=1000000;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<=1000000;i++) mu[i]=(mu[i-1]+mu[i]*i)%mod;
}
LL sum(LL x) {return x*(x+1)%mod*500000004%mod;}
LL solve(LL x)
{
if(x<=1000000) return mu[x];
if(Sum[n/x]!=0) return Sum[n/x];
LL ans=1,j;
for(LL i=2;i<=x;i=j+1)
{
j=x/(x/i);
ans-=(sum(j)-sum(i-1))%mod*solve(x/i)%mod;
ans%=mod;
}
Sum[n/x]=ans;
return ans;
}
LL calcp(LL n)
{
LL ans=0,j;
for(LL i=1;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans+(j-i+1)*sum(n/i)%mod)%mod;
}
return ans;
}
LL calcq(LL n)
{
LL ans=0,j;
for(LL i=1;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans+(sum(j)-sum(i-1))%mod*(n/i)%mod)%mod;
}
return ans;
}
int main()
{
pre();
scanf("%lld",&n);
LL ans=0,j;
for(LL i=1;i<=n;i=j+1)
{
j=n/(n/i);
ans=(ans+(solve(j)-solve(i-1))%mod*calcp(n/i)%mod*calcq(n/i)%mod)%mod;
}
printf("%lld",(ans+mod)%mod);
}