Cod sursa(job #2330094)
| Utilizator | Data | 27 ianuarie 2019 20:43:04 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
#include <vector>
int main()
{
std::ifstream fin("ciur.in");
std::ofstream fout("ciur.out");
int n;
fin >> n;
int cnt = 1, stop = (n - 3) / 2;
std::vector<bool> is_prim(stop + 1, true);
if (n > 2)
{
for (int i = 0; i <= stop; ++i)
if (is_prim[i])
{
cnt++;
for (int j = i + 2 * i + 3; j <= stop; j += 2 * i + 3)
is_prim[j] = false;
}
}
fout << cnt << std::endl;
return 0;
}