Cod sursa(job #1652205)

Utilizator razvandRazvan Dumitru razvand Data 14 martie 2016 19:27:29
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int Pmax = 1e8;
int phi[Pmax+10];
int i,j;

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

int main() {
    int n;
    in >> n;
    long long s = 0;

    bagaphi(n);

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

    out << s*2-1;

    return 0;
}