Cod sursa(job #2780917)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 8 octombrie 2021 09:51:03
Problema Fractii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 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 ) {
            phi[i]--;
            for ( int j = 2 * i; j <= n; j += i ) {
                phi[j] = phi[j] * ( i - 1 ) / i;
        }            }
        s += phi[i];
    }
    fout << 2 * s + 1;
    
    return 0;
}