Cod sursa(job #2476745)

Utilizator MarianConstantinMarian Constantin MarianConstantin Data 19 octombrie 2019 11:19:02
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
#define ll long long

using namespace std;

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

const int MAXN = 1e6;
ll phi[MAXN + 1], n;

void initialize() {
    for (int i = 2; i <= n; ++i)
        phi[i] = i - 1;
}

ll solve() {
    ll sol = 1;
    for (int i = 2; i <= n; ++i) {
        sol += (2 * phi[i]);
        for (int j = 2 * i; j <= n; j += i)
            phi[j] -= phi[i];
    }
    return sol;
}

int main() {
    fin >> n;
    initialize();
    fout << solve();
    return 0;
}