Cod sursa(job #875674)
| Utilizator | Data | 10 februarie 2013 17:13:11 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#include <bitset>
using namespace std;
int main() {
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n; fin >> n;
bitset<2000001> sieve;
for (int i=3,j; i<=n; ) {
j=i*i;
if (j<0) break;
for (; j<=n; j+=(i<<1)) {
sieve.set(j);
}
while ((i+=2)<=n && sieve[i]);
}
fout << n-n/2-sieve.count();//1 counted,2 not counted
return 0;
}
