Cod sursa(job #2742570)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 21 aprilie 2021 10:17:58
Problema Fractii Scor 0
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 - 1;
    }
    for(int i = 2; i <= N; i++) {
        if(phi[i] == i) {
            phi[i]--;
            for(int j = i + i; 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;
}