标签:
1个数N(N <= 10^9)
公约数之和
6
15
/* * Author: sweat123 * Created Time: 2016/6/27 14:01:46 * File Name: main.cpp */ #include<set> #include<map> #include<queue> #include<stack> #include<cmath> #include<string> #include<vector> #include<cstdio> #include<time.h> #include<cstring> #include<iostream> #include<algorithm> #define INF 1<<30 #define MOD 1000000007 #define ll long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define pi acos(-1.0) using namespace std; const int MAXN = 1000000; int n; ll ef(int n) { ll cnt = n; int i; for(i = 2; i * i <= n; i++){ if(n % i == 0) { cnt -= cnt / i; // (x-x/p1) *(1-1/p2)*(1-1/p3)*(1-1/p4)..... while(n % i == 0) n /= i; } } if(n > 1) cnt -= cnt / n; return cnt; } int main(){ while(~scanf("%d",&n)){ ll ans = 0; for(int i = 1; i <= (int)sqrt(n); i++){ if(n % i == 0){ ans += ef(n / i) * i; if(n / i != i){ ans += ef(i) * (n / i); } } } printf("%lld\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/sweat123/p/5620086.html