Cod sursa(job #992186)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 1 septembrie 2013 13:50:25
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>
#define nmax 1000005

using namespace std;

ifstream in("fractii.in");
ofstream out("fractii.out");

int n,phi[nmax];
long long s;

int main()
{
    in >> n;
        for (int i=2; i<=n; i++)
        phi[i]=i-1;
        for (int i=2; i<=n; i++)
            for (int j=2*i; j<=n; j+=i)
                phi[j]-=phi[i];
        for (int i=2; i<=n; i++)
            s+=phi[i];
    s=s*2+1;
    out << s;
    return 0;
}