Cod sursa(job #2781003)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 8 octombrie 2021 11:45:15
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>
#define limit 2000000

using namespace std;

ifstream cin("ciur.in");
ofstream cout("ciur.out");

int phi[limit + 1];
int n;

void ciur(){

    for(int i = 2; i <= limit; i++)
        phi[i] = i;
    
    for(int i = 2; i <= limit; i++){
        if(phi[i] == i){
            for(int j = i; j <= limit; j += i)
                phi[j] = phi[j] / i * (i - 1);
        }
    }

}


int main(){

    ciur();
    cin >> n;
    cout << phi[n];

}