bzoj4916 发表于 2018-11-02 | 分类于 题解 | 阅读数 次 链接:bzoj4916 题解 显然第一问答案是1,第二问求 设 根据杜教筛的套路 设 则 显然 即 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061#include<iostream>#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 qpow(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("1\n%lld\n",solve(n)); } return 0;}