Cod sursa(job #3363600)

Utilizator alex.iovita.23@gmail.comIovita Alexandru [email protected] Data 19 august 2026 16:58:29
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include<bits/stdc++.h>

using namespace std;

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

const int DIM = 1e6;
int phi[DIM + 5];

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

int main(){
    int n; fin >> n;
    prelucru();
    long long rez=  1;
    for(int i = 2 ; i <= n ; i++) rez += 2 * phi[i];
    fout << rez;
}