Cod sursa(job #942680)

Utilizator AnonymouslegionAnonymous Anonymouslegion Data 23 aprilie 2013 11:39:21
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<fstream>

using namespace std;

long long phi[1000005];

int main(){
  ifstream in("fractii.in");
  ofstream out("fractii.out");

  int n;
  in >> n;

  for(int i = 2; i <= n; ++i)
    phi[i] = i;

  for(int i = 2; i <= n; ++i)
    if(phi[i] == i)
      for(int j = i; j <= n; j += i)
        phi[j] = (long long)phi[j] * (i - 1) / i;

  long long ans = 0;
  for(int i = 2; i <= n; ++i)
    ans += phi[i];
  ans = ans * 2 + 1;

  out << ans;

  return 0;
}