Cod sursa(job #1296683)

Utilizator andrei.arnautuAndi Arnautu andrei.arnautu Data 21 decembrie 2014 13:52:24
Problema Fractii Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>

using namespace std;

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

long long int cnt, V[1000013], N;

int main()
{
    in >> N;
    for(int i = 2 ; i <= N ; ++i )
        V[i] = i - 1;

    for(int i = 2 ; i <= N ; ++i )
    {
        cnt += V[i];
        for(int j = i * 2 ; j <= N ; j += i )
            V[j] -= V[i];
    }

    out << 2 * cnt + 1;

    return 0;
}