# loj 6053 简单的函数 —— min_25筛

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int const xn=1e6+5,mod=1e9+7;
int m,f[xn],h[xn],pri[xn],cnt,sqr,ps[xn];
ll n,w[xn]; bool vis[xn];
ll pw(ll a,ll b){a%=mod; b%=(mod-1); ll ret=1; for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod; return ret;}
int upt(ll x){while(x>=mod)x-=mod; while(x<0)x+=mod; return x;}
void init()
{
for(int i=2;i<=sqr;i++)
{
if(!vis[i])pri[++cnt]=i,ps[cnt]=upt(ps[cnt-1]+i);
for(int j=1;j<=cnt&&(ll)i*pri[j]<=sqr;j++)
{
vis[i*pri[j]]=1;
if(i%pri[j]==0)break;
}
}
}
int Id(ll x)
{
if(x>sqr)return n/x;//>!
else return m-x+1;
}
int S(ll x,int y)
{
if(x<=1||pri[y]>x)return 0;
int k=Id(x);
int ret=upt((ll)f[k]-h[k]-(ps[y-1]-y+1));
if(y==1)ret=upt(ret+2);
for(int i=y;i<=cnt&&(ll)pri[i]*pri[i]<=x;i++)
{
ll p0=pri[i],p1=(ll)pri[i]*pri[i];//ll
for(int k=1;p1<=x;k++,p0=p1,p1*=pri[i])
ret=upt(ret+(ll)(pri[i]^k)*S(x/p0,i+1)%mod+(pri[i]^(k+1)));
}
return ret;
}
int main()
{
scanf("%lld",&n); sqr=sqrt(n); int inv2=pw(2,mod-2); init();
for(ll i=1,j;i<=n;i=j+1)
{
w[++m]=n/i; j=n/(n/i);
f[m]=(ll)upt(w[m]+2)*upt(w[m]-1)%mod*inv2%mod;//upt!
f[m]=upt(f[m]);//筛质数和
h[m]=upt(w[m]-1);//筛质数个数
}
for(int j=1;j<=cnt;j++)//j=1
for(int i=1;i<=m&&w[i]>=(ll)pri[j]*pri[j];i++)
{
int k=Id(w[i]/pri[j]);
f[i]=upt(f[i]-(ll)pri[j]*(f[k]-ps[j-1])%mod);
h[i]=upt(h[i]-h[k]+j-1);
}
printf("%d\n",upt(S(n,1)+1));
return 0;
}

posted @ 2019-01-17 11:05  Zinn  阅读(234)  评论(0编辑  收藏  举报