Cod sursa(job #2444321)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 31 iulie 2019 10:45:21
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>

#define NMAX 1000005
#define ll long long

using namespace std;

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

ll n;
int v[NMAX];

int main()
{
    fin >> n;

    ll cnt = 0;
    for(int i = 2; i <= n; i++)
        v[i] = i-1;

    for(int i = 2; i <= n/2; i++)
        for(int j = 2*i; j <= n; j+=i)
            v[j] -= v[i];

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

    fout << 2 * cnt + 1;
    return 0;
}