Advertisement
Guest User

totient

a guest
Aug 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <cmath>
  6. #include <math.h>
  7. #include <queue>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. ifstream fin("fractii.in");
  13. ofstream fout("fractii.out");
  14.  
  15. double phi(int n)
  16. {
  17.     double rez = n;
  18.     for (int i = 2; i*i <= n; i++)
  19.     {
  20.         if (n%i == 0) {
  21.             while (n%i == 0) n /= i;
  22.             rez = rez * (1.0 - (1.0 / (double)i));
  23.         }
  24.     }
  25.     if (n > 1)
  26.         rez = rez * (1.0 - (1.0 / (double)n));
  27.  
  28.     return rez;
  29. }
  30.  
  31. int main()
  32. {
  33.     ios_base::sync_with_stdio(false);
  34.     int n;
  35.     long long total = 0;
  36.     fin >> n;
  37.     total = 0;
  38.     for (int i = 1; i <= n; i++)
  39.         total += round(phi(i));
  40.     fout << total*2 - 1;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement