Cod sursa(job #3231330)
Utilizator | Data | 25 mai 2024 18:24:55 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
bool nemPrim[2000001] = {};
int main(){
int primekSzama = 0;
int n;
std::ifstream bem("ciur.in");
bem >> n;
bem.close();
nemPrim[0] = true;
nemPrim[1] = true;
for(int i = 2; i * i < n; i++){
if(!nemPrim[i]){
for(int j = i*i; j <= n; j += i){
nemPrim[j] = true;
}
}
}
for(int i = 0; i < n; i++){
if(!nemPrim[i]){
primekSzama++;
}
}
std::ofstream kim("ciur.out");
kim << primekSzama;
return 0;
}