題目
已知
現在請求出下面式子的值
由於值可能過大所以請對 10^9+7 取模
分析
因爲
對於每個質因子分開考慮,
現在考慮如何求
設
發現
於是
設
於是
杜教篩一下.
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
const int maxlongint=2147483647;
const long long mo=1e9+7;
const int lim=1e5+7;
const int N=10000005;
using namespace std;
#define sqr(x) (1ll*(x)*(x)%mo)
#define val(x,y) (1ll*(y-x+1)*(x+y)/2%mo)
int p[N],mu[N],n,ha[lim+5][2],s[N],ans;
bool bz[N];
int get(int v)
{
int x;
for(x=v%lim;ha[x][0] && ha[x][0]!=v;(++x)-=x>=lim?lim:0);
return x;
}
int S(int m)
{
if(m<=N-5) return s[m];
int pos=get(m);
if(ha[pos][0]) return ha[pos][1];
ha[pos][0]=m;
int la=0,sum=0;
for(int i=2;i<=m;i=la+1)
{
la=m/(m/i);
sum=(1ll*sum+1ll*val(i,la)*S(m/i))%mo;
}
return ha[pos][1]=(1-sum+mo)%mo;
}
int main()
{
freopen("2026.in","r",stdin);
//freopen("2026.out","w",stdout);
scanf("%d",&n);
mu[1]=s[1]=1;
for(int i=2;i<=N-5;i++)
{
if(!bz[i]) mu[p[++p[0]]=i]=-1;
s[i]=(s[i-1]+mu[i]*i+mo)%mo;
for(int j=1,k;j<=p[0] && (k=i*p[j])<=N-5;j++)
{
bz[k]=true;
if(i%p[j]==0) break;
mu[k]=-mu[i];
}
}
int la=1;
for(int i=1;i<=n;i=la+1)
{
la=n/(n/i);
ans=(1ll*ans+1ll*(S(la)-S(i-1)+mo)*(n/i))%mo;
}
printf("%lld",sqr(ans));
}