Cod sursa(job #2780922)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 8 octombrie 2021 09:53:19
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <fstream>
using namespace std;
const int nmax = 1e6;
int phi[nmax + 1];
ifstream fin ( "fractii.in" );
ofstream fout ( "fractii.out" );
int main() {
    int n;
    long long s ( 0 );
    fin >> n;
    for ( int i = 1; i <= n; i++ )
        phi[i] = i;
    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 );
        s += phi[i];
    }
    fout << 2 * s + 1;
    
    return 0;
}