Cod sursa(job #3304471)
| Utilizator | Data | 23 iulie 2025 23:16:01 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n, cnt;
bool c[2000005];
void ciur() {
c[0] = 1, c[1] = 1;
for (int i = 4; i <= n; i += 2)
c[i] = 1;
for (int i = 3; i * i <= n; i++)
if (c[i] == 0)
for (int j = i; i * j <= n; j += 2)
c[i * j] = 1;
}
int main() {
fin >> n;
ciur();
for (int i = 1; i <= n; i++)
if (!c[i])
cnt++;
fout << cnt;
return 0;
}
