Cod sursa(job #2781020)

Utilizator ruxiTTutunaru Ruxandra ruxiT Data 8 octombrie 2021 12:20:42
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>

const int VMAX = 1000001;

int e[VMAX];

using namespace std;

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

int main()
{
    int n, i, j;
    long long s = 0;
    fin >> n;
    for (i = 2; i <= n; i++) {
        e[i] = i;
    }
    for (i = 2; i <= n; i++)
        if (e[i] == i)
            for (j = i; j <= n; j += i)
                e[j] = e[j] / i * (i - 1);
    for (i = 2; i < n + 2; i++)
        s += e[i];
    fout << 2 * s + 1;
    return 0;
}