Cod sursa(job #2114067)

Utilizator oldatlantianSerban Cercelescu oldatlantian Data 25 ianuarie 2018 14:44:36
Problema Fractii Scor 100
Compilator cpp Status done
Runda ichb_10 Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;

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

using i64 = long long;

const int N = 1e6 + 5;

i64 phi[N];

int main(void) {
    int n;
    i64 ans;

    fi >> n;

    for (int i = 1; i <= n; ++i)
        phi[i] = i;

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

    ans = 0;
    for (int i = 1; i <= n; ++i)
        ans+= phi[i];
    fo << 2 * ans - 1 << endl;

    return 0;
}