Cod sursa(job #3363599)

Utilizator Cyb3rBoltSbora Ioan-David Cyb3rBolt Data 19 august 2026 16:52:54
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int DIM = 1e6;
int phi[DIM + 3];

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()
{
    prelucru();
    int n; fin >> n;
    long long rez = 1;
    for(int i=2; i<=n; i++) rez += 2 * phi[i];
    fout << rez;

    return 0;
}