Cod sursa(job #2549833)
| Utilizator | Data | 18 februarie 2020 06:25:04 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n;
bitset<2000001> P;
void Ciur()
{
P.set();
P[0] = P[1] = false;
for (int i = 2; i * i <= n; ++i)
{
if (P[i])
{
for (int j = i * i; j <= n; j += i)
P[j] = false;
}
}
}
int main()
{
int cnt = 0;
fin >> n;
Ciur();
for (int i = 1; i <= n; ++i)
{
if (P[i])
++cnt;
}
fout << cnt;
return 0;
}
