Pagini recente » Cod sursa (job #1376920) | Cod sursa (job #320485) | Cod sursa (job #3280841) | Cod sursa (job #2315684) | Cod sursa (job #2692803)
#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 = 0;
seive[0] = seive[1] = true;
cin >> limit;
for(int i = 4; i <= limit; i += 2){
seive[i] = true;
}
for(int i = 3; i * i <= limit; i += 2){
if(!seive[i]){
for(int j = i * i; j <= limit; j += 2 * i){
seive[j] = true;
}
}
}
for(int i = 2; i <= limit; ++i){
if(!seive[i]){
countPrimeNumber++;
}
}
cout << countPrimeNumber;
return 0;
}