Cod sursa(job #2780125)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 6 octombrie 2021 08:56:10
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int DIM = 1e6;
int N;
long long phi[DIM + 4], rez;
void getphi(int N) {
    for(int i = 1; i <= N; i++) {
        phi[i] = i;
    }
    for(int i = 2; i <= N; i++) {
        if(phi[i] == i) {
            phi[i]--;
            for(int j = 2; j * i <= N; j++) {
                phi[j * i] = phi[j * i] * (i - 1) / i;
        }            }

        rez += phi[i];
    }
}
int main() {
    fin >> N;
    getphi(N);
    fout << 2 * rez + 1;
    return 0;
}