[联合集训6-9] Psy 组合数学+杜教筛

${F}_{n}=\frac{1}{n}\left({10}^{n}-\sum _{d|n,d

$\sum _{i=1}^{n}{G}_{i}=\sum _{i=1}^{n}i\cdot {10}^{i}-\sum _{i=1}^{n}\sum _{d|i,d

$\sum _{i=1}^{n}{G}_{i}=\frac{n\cdot {10}^{n+1}-\frac{{10}^{n+1}-1}{9}+1}{9}-\sum _{k=2}^{n}\sum _{i=1}^{⌊\frac{n}{k}⌋}{G}_{k}$

include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int mod=1000000007;
const int R=100000;
const int T=3000000;
ll n,i9,i2;
int mg[R+5],g[T+5];
ll ksm(ll a,ll b)
{
ll r=1;
for(;b;b>>=1,a=a*a%mod)
if(b&1) r=r*a%mod;
return r;
}
ll solve(ll x)
{
ll m=n/x,pp,ans;
if(m<T) return g[m];x=n/m;
if(x<R&&mg[x]>=0) return mg[x];
pp=ksm(10,m+1);
ans=(pp*(m-i9+mod)+i9+1)%mod*i9%mod;
for(ll l=2,r;l<=m;l=r+1)
{
r=m/(m/l);
ll s=((l+r)%mod)*((r-l+1)%mod)%mod*i2%mod;
ans=(ans-s*solve(x*l)%mod+mod)%mod;
}
if(x<R) mg[x]=ans;
return ans;
}

int main()
{
scanf("%lld",&n);
memset(mg,-1,sizeof(mg));
i9=ksm(9,mod-2);
i2=ksm(2,mod-2);
g[1]=10;
for(int i=2;i<=T;i++)
g[i]=10ll*g[i-1]%mod;
for(int i=1;i<=T;i++)
{
for(int j=(i<<1);j<=T;j+=i)
g[j]=(g[j]+mod-g[i])%mod;
g[i]=((ll)g[i]*i+g[i-1])%mod;
}
printf("%lld",solve(1));
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120