Cod sursa(job #2576039)
| Utilizator | Data | 6 martie 2020 16:56:27 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
const int MAXN = 2e6;
int n, cnt;
bool c[MAXN + 1];
void ciur() {
c[0] = 1;
c[1] = 1;
cnt = 1;
for (int i = 4; i <= n; i += 2) c[i] = 1;
for (int i = 3; i <= n; i += 2) {
if (!c[i]) {
++ cnt;
for (int j = i + i; j <= n; j += i)
c[j] = 1;
}
}
}
int main() {
in >> n;
ciur();
out << cnt;
return 0;
}