Cod sursa(job #809244)
Utilizator | Data | 8 noiembrie 2012 06:54:13 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
inline int next_int() {
int d;
scanf("%d", &d);
return d;
}
bool P[2000001];
int main() {
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n = next_int();
for (int i = 2; i * i <= n; i++) {
if (P[i] == 0) {
for (int j = i * i; j <= n; j += i) {
P[j] = 1;
}
}
}
int ans = 0;
for (int i = 2; i <= n; i++) {
if (P[i] == 0) {
ans++;
}
}
printf("%d", ans);
return 0;
}