题目:http://cojs.tk/cogs/problem/problem.php?pid=2431
题解:
其实这道题真心简单,不要被数据范围迷惑。
对于F(x)函数,我们把x分解为p1^a1*p2^a2*……*pn^an
F(x)=(a1+1)*(a2+1)*……*(an+1);
直接枚举N的因子,已知N的因子个数是logN个,所以后面的就直接暴力就可以了,效率是log(N)*,10^15可以过掉
#include <cstdio> #include <cmath> using namespace std; typedef long long ll; const int MAXN=10000005; ll N,Ans,tot; ll ans_1[MAXN],ans_2[MAXN],Tmp[MAXN]; ll Phi(ll x){ ll res=x,k=sqrt(x); for(int i=2;i<=k;++i){ if(x%i==0){ res-=res/i; while(x%i==0)x/=i; } } if(x>1)res-=res/x; return res; } ll F(ll x){ Tmp[0]=0; int k=sqrt(x); ll ans=1; for(int i=2;i<=k;i++){ while(x%i==0){ Tmp[++Tmp[0]]=i; x/=i; } } if(x>1)Tmp[++Tmp[0]]=x; if(!Tmp[0])return 0; for(int i=1,j=i;i<=Tmp[0];i++){ j=i; while(Tmp[j] == Tmp[j+1] && j<Tmp[0])j++; ans*=(j-i+2); i=j; } return ans; } int main(){ freopen("aimiliyadehelp.in","r",stdin); freopen("aimiliyadehelp.out","w",stdout); scanf("%lld",&N); int k=sqrt(N); for(int i=1;i<=k;++i){ if(N%i==0){ ans_1[++ans_1[0]]=i; if(i*i!=N)ans_1[++ans_1[0]]=N/i; } } for(int i=1;i<=ans_1[0];++i) Ans+=F(ans_1[i])*Phi(N/ans_1[i]); printf("%lld ",Ans); fclose(stdin); fclose(stdout); return 0; }