Cod sursa(job #2608195)
Utilizator | Data | 30 aprilie 2020 19:11:33 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <cstdio>
int main() {
unsigned long n, i, j, rez = 0;
bool v[2000005] {};
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
for(i = 3; i <= n; i += 2)
if(v[i] == 0) {
++rez;
if(i <= 65535)
j = i*i;
else
j = i << 1;
for(j; j <= n; j += (i << 1))
v[j] = 1;
}
printf("%d ", rez+1);
}