Cod sursa(job #2214263)
| Utilizator | Data | 18 iunie 2018 17:11:01 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
const int MAXN = 2e6;
bool c[MAXN + 2];
void ciur(int n) {
c[0] = c[1] = 1;
for (int i = 4; i <= n; i += 2)
c[i] = 1;
for (int i = 3; i * i <= n; ++ i) {
for (int j = i * i; j <= n; j += 2 * i) {
c[j] = 1;
}
}
}
int main() {
int n;
in >> n;
ciur(n);
int cnt = 1;
for (int i = 3; i <= n; i += 2) {
if (!c[i])
++ cnt;
}
out << cnt;
return 0;
}