Cod sursa(job #1008661)
| Utilizator | Data | 11 octombrie 2013 15:42:55 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <cstdio>
#include <bitset>
using namespace std;
bitset<1000010> e;
int main() {
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n;
scanf("%d", &n);
for (int i = 3; i * i < n; i += 2) {
if (e[i >> 1]) {
continue;
}
for (int j = i * i; j <= n; j += (i << 1)) {
e[j >> 1] = true;
}
}
int res = 1;
for (int i = 3; i <= n; i += 2) {
if (!e[i >> 1]) {
++res;
}
}
printf("%d\n", res);
return 0;
}
