Cod sursa(job #1296667)

Utilizator andrei.arnautuAndi Arnautu andrei.arnautu Data 21 decembrie 2014 13:47:55
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>
#define MaxN ( 1 << 20 )

using namespace std;

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

int cnt, V[MaxN], N;

int main()
{
    in >> N;
    for(int i = 1 ; 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;
}