Cod sursa(job #2907387)

Utilizator rares89_Dumitriu Rares rares89_ Data 30 mai 2022 00:37:20
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>

using namespace std;

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

int n, phi[1000005];
long long int s = 1LL;

int main() {
    fin >> n;
    fin.close();
    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++) {
                phi[i * j] = phi[i * j] / i * (i - 1);
            }
        }
        s += 2LL * phi[i];
    }
    fout << s;
    return 0;
}