Cod sursa(job #1599048)
Utilizator | Data | 13 februarie 2016 16:10:11 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
#include <iostream>
#include <bitset>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int NMAX = 2000000;
bitset<NMAX + 1> check;
int eratostene(int x) {
int nrPrimes = 0;
for(int i = 2; i * i <= x; ++i) {
if(check[i] == 0)
for(int j = i * i; j <= x; j += i)
check[j] = 1;
}
for(int i = 2; i <= x ; ++i)
if(check[i] == 0)
nrPrimes++;
return nrPrimes;
}
int main() {
int x;
fin >> x;
fout << eratostene(x);
return 0;
}