标签:like long ever ber pre iostream sam lan ica
2 6
3 15
解题思路:
AC代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <map> 5 #include <vector> 6 #include <set> 7 using namespace std; 8 typedef long long LL; 9 const int maxn = 1e6+5; 10 LL n, ans; 11 LL get_Euler(LL x){ 12 LL res = x; 13 for(LL i = 2LL; i * i <= x; ++i) { 14 if(x % i == 0) { 15 res = res / i * (i - 1); 16 while(x % i == 0) x /= i; 17 } 18 } 19 if(x > 1LL) res = res / x * (x - 1); 20 return res; 21 } 22 23 int main(){ 24 while(cin >> n) { 25 ans = 0LL; 26 for (LL i = 1LL; i * i <= n; ++i) { 27 if(n % i == 0) { 28 ans += i * get_Euler(n / i); 29 if(i * i != n) ans += n / i * get_Euler(i); ///避免重复计数 30 } 31 } 32 cout << ans << endl; 33 } 34 return 0; 35 }
题解报告:poj 2480 Longge's problem(欧拉函数)
标签:like long ever ber pre iostream sam lan ica
原文地址:https://www.cnblogs.com/acgoto/p/10284800.html