Cod sursa(job #2418885)

Utilizator SemetgTemes George Semetg Data 6 mai 2019 18:26:26
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
#include <vector>
using namespace std;

const string FILE_NAME = "fractii";
const int N_MAX { 1000005 };

ifstream in { FILE_NAME + ".in" };
ofstream out { FILE_NAME + ".out" };

int N;
vector<int> phi(N_MAX);
int64_t sol { 1 };

int main() {
    in >> 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;
        
        sol += 2 * phi[i];
    }
    
    out << sol;
}