题目大意
求
解题分析
注意,所有gcd(x,n)最后都是n的因数。所以可以对因数分类,设
如果
复杂度:
时间:
空间:
#include<cmath>
#include<cstdio>
#define LL long long
using namespace std;
int n,S,p[10005];
LL ans;
int getp(int x){
int sum=x; for (int i=2,S=sqrt(x);i<=S;i++) if (x%i==0) {sum=sum/i*(i-1); while (x%i==0) x/=i;}
if (x>1) sum=sum/x*(x-1); return sum;
}
int main()
{
freopen("gcda.in","r",stdin);
freopen("gcda.out","w",stdout);
scanf("%d",&n); S=sqrt(n); ans=0;
for (int i=1;i<=S;i++)
if (n%i==0){
int t=n/i;ans+=(LL)i*getp(t);
if (i!=t) ans+=(LL)t*getp(i);
}
printf("%lld",ans);
return 0;
}