Cod sursa(job #2692802)
Utilizator | Popescu Serban SerbaP123 | Data | 3 ianuarie 2021 19:47:26 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
#include <bitset>
#define nmax 2000000
using namespace std;
ifstream cin("ciur.in");
ofstream cout("ciur.out");
bitset <nmax + 1> seive;
int main(){
int limit, countPrimeNumber = 1;
seive[0] = seive[1] = true;
cin >> limit;
for(int i = 4; i <= limit; i += 2){
seive[i] = true;
}
for(int i = 3; i <= limit; i += 2){
if(!seive[i]){
countPrimeNumber++;
for(int j = 2 * i; j <= limit; j += i){
seive[j] = true;
}
}
}
cout << countPrimeNumber;
return 0;
}