Cod sursa(job #3341068)
| Utilizator | Data | 17 februarie 2026 19:25:44 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#define NMAX (1U << 21)
int main()
{
int n;
int cnt = 0;
char sieve[NMAX];
std::ifstream fin("ciur.in");
std::ofstream fout("ciur.out");
fin >> n;
for (int i = 2; i <= n; ++i)
sieve[i] = 1;
for (int i = 2; i <= n; ++i)
if (sieve[i]) {
for (int j = i + i; j <= n; j += i)
sieve[j] = 0;
++cnt;
}
fout << cnt << '\n';
fin.close();
fout.close();
return 0;
}
