Cod sursa(job #3350289)

Utilizator hyper27Antonio Nicolae hyper27 Data 6 aprilie 2026 22:31:09
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

int main() {
    int n;
    std::ifstream fin("fractii.in");
    std::ofstream fout("fractii.out");
    fin >> n;

    long long phy[1000001];
    for (int i = 0; i <= n; i++) { phy[i] = i; }

    for(int i = 2; i <= n; i++) {
        if (phy[i] == i) {
            for(int j = i ; j <= n; j += i) {
                phy[j] -= phy[j] / i;
            }
        }
    }

    long long result = 1;
    for (int i = 2; i <= n; i++) {
        result += 2 * phy[i];
    }

    fout << result;

}