Pagini recente » Cod sursa (job #2603018) | Cod sursa (job #695061) | Cod sursa (job #2801548) | Cod sursa (job #1621640) | Cod sursa (job #1599048)
#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;
}