SHARE
TWEET

totient

a guest Aug 24th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top