Problem Description:
LL Eular(LL n) { LL i, ans = 1; for (i = 2; i*i <= n; i++) { if (n % i == 0) { ans *= i-1; n /= i; while (n > 0 && n % i == 0) { n /= i; ans *= i; } } } if (n > 1) ans *= n-1; return ans; }
此题代码:
#include<stdio.h> #include<string.h> #include<queue> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; const int MOD=1e9+7; typedef long long LL; LL Eular(LL n) { LL i, ans = 1; for (i = 2; i*i <= n; i++) { if (n % i == 0) { ans *= i-1; n /= i; while (n > 0 && n % i == 0) { n /= i; ans *= i; } } } if (n > 1) ans *= n-1; return ans; } int main () { LL n, k, ans, i, num; while (scanf("%lld %lld", &n, &k) != EOF) { ans = num = 0; if (k == 2 || n == 1) ans = 1; else if (k == 1) { for (i = 1; i*i <= n; i++) { if (n % i == 0) { if (i*i != n) ans = (ans + Eular(n/i)*Eular(i)*2) % MOD; else ans = ans = (ans + Eular(n/i)*Eular(i)) % MOD; } } } printf("%lld\n", ans); } return 0; }
HDU 4983 Goffi and GCD(欧拉函数模板)
原文:http://www.cnblogs.com/syhandll/p/4917051.html