poj2480 数论
题目:求。可以枚举gcd即:
变形一下:
,这样就转化为:个gcd为g的数
答案为:
#include<cstdio>
#include<cstring>
#include<algorithm>
#ifdef WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define ll long long
using namespace std;
ll n;
inline int phi(int x){
int ans=x;
for(int i=2;1ll*i*i<=1ll*x;i++){
if(x%i==0) {
ans=ans/i*(i-1);
while(x%i==0) x/=i;
}
}
if(x>1) ans=ans/x*(x-1);
return ans;
}
int main(){
// freopen("poj2480.in","r",stdin);
while(scanf(LLD,&n)!=EOF){
ll ans=0;
for(int i=1;1ll*i*i<=1ll*n;i++){
if(n%i==0){
int x=phi(n/i);ans+=1ll*x*i;
if(i*i!=n) {
int y=phi(i);ans+=1ll*y*(n/i);
}
}
}
printf(LLD"\n",ans);
}
return 0;
}