Cod sursa(job #2662906)
| Utilizator | Data | 24 octombrie 2020 20:12:59 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <cstdio>
using namespace std;
const int NMAX = 2000000;
const int BASE = 64;
long long ciur[NMAX / BASE + 1];
int main() {
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n, ans = 0;
scanf("%d", &n);
ciur[0] = 3;
for(int i = 2; i <= n; i++)
if(!( ciur[i / BASE] & ((long long)1 << (i % BASE)) )) {
ans++;
for(int j = 2 * i; j <= n; j += i)
ciur[j / BASE] |= ((long long)1 << (j % BASE));
}
printf("%d", ans);
return 0;
}
