Cod sursa(job #2702150)

Utilizator DragosC1Dragos DragosC1 Data 2 februarie 2021 23:41:11
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
using namespace std;

int main() {
    int x, d, r;

    ifstream f("ciur.in");
    f >> x;
    f.close();

    d = 2; r = x;
    while (x > 1) {
        if (x % d == 0) {
            r = r / d * (d - 1);
            while (x % d == 0)
                x /= d;
        }
        d++;
        if (d * d > x)
            d = x;
    }

    ofstream g("ciur.out");
    g << r;
    g.close();
    return 0;
}