D.cpp 949 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using LL=long long;
  4. const int MAXN = 2e6 + 10;
  5. vector<int> primes = {2, 3};
  6. void init() {
  7. for (int k = primes.back() + 2; k <= MAXN; k += 2) {
  8. bool flag = true;
  9. for (auto p:primes) {
  10. if (p * p > k)break;
  11. if (k % p == 0) {
  12. flag = false;
  13. break;
  14. }
  15. }
  16. if (flag)primes.push_back(k);
  17. }
  18. }
  19. int main() {
  20. init();
  21. for (int n; cin >> n;) {
  22. map<int, int> k;
  23. for (auto p:primes) {
  24. if (p * p > n)break;
  25. while (n % p == 0) {
  26. ++k[p];
  27. n /= p;
  28. }
  29. }
  30. if (n > 1)k[n]++;
  31. LL ans = 1;
  32. for (auto p:k) {
  33. if (p.second == 1)ans *= (p.first - 1);
  34. else ans *= pow(p.first, p.second) - pow(p.first, p.second - 1);
  35. }
  36. cout << ans << endl;
  37. }
  38. return 0;
  39. }