题意
n<=1010
n
<=
10
10
分析
直接上Min_25筛搞一搞就好了。
如果还不会Min_25筛的话可以点一下这里或去看zzq的博客。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=200005;
const int MOD=1000000007;
int tot,s[N],g[N],id1[N],id2[N],B,m,h[N];
bool not_prime[N];
LL n,w[N],p[N];
void get_prime(int n)
{
for (int i=2;i<=n;i++)
{
if (!not_prime[i]) p[++tot]=i,s[tot]=(s[tot-1]+i)%MOD;
for (int j=1;j<=tot&&i*p[j]<=n;j++)
{
not_prime[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
}
int F(LL x,int y)
{
if (x<=1||p[y]>x) return 0;
int k=x<=B?id1[x]:id2[n/x],ans=(g[k]-s[y-1]-h[k]+y-1)%MOD;
if (y==1) ans+=2;
for (int i=y;i<=tot&&(LL)p[i]*p[i]<=x;i++)
{
LL t1=p[i],t2=(LL)p[i]*p[i];
for (int e=1;t2<=x;e++,t1=t2,t2=(LL)t2*p[i])
(ans+=((LL)F(x/t1,i+1)*(p[i]^e)%MOD+(p[i]^(e+1)))%MOD)%=MOD;
}
return ans;
}
int main()
{
scanf("%lld",&n);
B=sqrt(n);
get_prime(B);
for (LL i=1,last;i<=n;i=last+1)
{
last=n/(n/i);w[++m]=n/i;
h[m]=(w[m]-1)%MOD;
g[m]=(w[m]&1)?(w[m]+1)/2%MOD*(w[m]%MOD)%MOD:w[m]/2%MOD*(w[m]%MOD+1)%MOD;
g[m]--;
if (n/i<=B) id1[n/i]=m;
else id2[last]=m;
}
for (int j=1;j<=tot;j++)
for (int i=1;i<=m&&p[j]*p[j]<=w[i];i++)
{
int k=w[i]/p[j]<=B?id1[w[i]/p[j]]:id2[n/(w[i]/p[j])];
(g[i]-=(LL)p[j]*(g[k]-s[j-1])%MOD)%=MOD;
(h[i]-=h[k]-j+1)%=MOD;
}
int ans=F(n,1)+1;
printf("%d",(ans+MOD)%MOD);
return 0;
}