1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include <tr1/unordered_map> #include<algorithm> #define rep(i,x,y) for(register int i=x;i<=y;++i) #define repd(i,x,y) for(register int i=x;i>=y;--i) #define ll long long #define get(l,r) ((l+r)*(r-l+1)%mod*p2%mod) using namespace std; using namespace std::tr1; const int N=1e6+7; const ll mod=1e9+7; unordered_map<ll,ll> f; int m=1e6,vis[N],cnt; ll s[N],phi[N],p[N],p1,p2,n; ll (ll a,ll b){ ll res=1; while(b){ if(b&1)res=(res*a)%mod; a=a*a%mod; b>>=1; } return res; } void pre(){ phi[1]=1; rep(i,2,m){ if(!vis[i])p[++cnt]=i,phi[i]=i-1; for(int j=1;j<=cnt&&p[j]*i<=m;++j){ vis[p[j]*i]=1; if(i%p[j]==0){ phi[i*p[j]]=p[j]*phi[i]; break; } phi[i*p[j]]=(p[j]-1)*phi[i]; } } rep(i,1,m)s[i]=(phi[i]*i%mod+s[i-1])%mod; } ll solve(ll x){ if(x<=m)return s[x]; if(f.count(x))return f[x]; ll res=x*(x+1)%mod*(x*2+1)%mod*p1%mod; for(ll l=2,r=2;l<=x;l=r+1){ r=x/(x/l); res=(res-get(l,r)*solve(x/l)%mod+mod)%mod; } return f[x]=res; } int main(){ pre(); while(~scanf("%lld",&n)){ p1=qpow(6,mod-2);p2=qpow(2,mod-2); printf("1n%lldn",solve(n)); } return 0; }
|
近期评论