Cod sursa(job #2863548)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 6 martie 2022 21:01:06
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 MAX_N = 1000015;

int phi[MAX_N];

signed main (){
    ios_base::sync_with_stdio(false);
    fin.tie(nullptr);
    fout.tie(nullptr);

    long long n, sol;
    fin>>n;
    for(int i=1; i<=n; i++)
        phi[i] = i;

    sol = phi[1];
    for(int i=2; i<=n; i++){
        if(phi[i] == i)
            for(int j=i; j<=n; j+=i)
                phi[j] = phi[j] / i * (i-1);
        sol += 2 * phi[i];
    }

    fout<<sol;
    return 0;
}