题解
\(Min\_25\)筛有毒啊……肝了一个下午才看懂是个什么东西……
强无敌……
//minamoto#include#define R register#define ll long long#define fp(i,a,b) for(R int i=a,I=b+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)using namespace std;const int N=1e6+5,P=1e9+7,inv2=500000004;inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}int vis[N],p[N],sp[N],id1[N],id2[N],g[N],h[N];int sqr,tot,m;ll n,w[N];void init(int n){ fp(i,2,n){ if(!vis[i])p[++tot]=i,sp[tot]=add(sp[tot-1],i); for(R int j=1;1ll*i*p[j]<=n;++j){ vis[i*p[j]]=1; if(i%p[j]==0)break; } }}int s(ll x,int y){ if(x<=1||p[y]>x)return 0; int k=(x<=sqr)?id1[x]:id2[n/x]; int res=((1ll*g[k]-h[k]-sp[y-1]+y-1)%P+P)%P; if(y==1)res+=2; for(int i=y;i<=tot&&1ll*p[i]*p[i]<=x;++i){ ll p1=p[i],p2=1ll*p[i]*p[i]; for(int e=1;p2<=x;++e,p1=p2,p2*=p[i]) (res+=1ll*s(x/p1,i+1)*(p[i]^e)%P+(p[i]^(e+1)))%=P; }return res;}int main(){// freopen("testdata.in","r",stdin); scanf("%lld",&n); sqr=sqrt(n),init(sqr); for(R ll i=1,j;i<=n;i=j+1){ j=n/(n/i),w[++m]=n/i; w[m]<=sqr?id1[w[m]]=m:id2[n/w[m]]=m; h[m]=(w[m]-1)%P; g[m]=((w[m]+2)%P)*((w[m]-1)%P)%P*inv2%P; } fp(j,1,tot)for(R int i=1;i<=m&&1ll*p[j]*p[j]<=w[i];++i){ int k=(w[i]/p[j]<=sqr)?id1[w[i]/p[j]]:id2[n/(w[i]/p[j])]; g[i]=(g[i]-1ll*p[j]*(g[k]-sp[j-1])%P)%P,g[i]=(g[i]+P)%P; h[i]=(h[i]-h[k]+j-1)%P,h[i]=(h[i]+P)%P; } printf("%d\n",s(n,1)+1); return 0;}