Cod sursa(job #2077678)
| Utilizator | Data | 28 noiembrie 2017 14:18:21 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
bitset<2000001> a;
int main()
{
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int i, j, n;
fin >> n;
a[0] = a[1] = 1;
for (i = 4; i <= n; i += 2)
a[i] = 1;
for (i = 3; i * i <= n; i += 2)
if (!a[i])
for (j = i * i; j <= n; j += 2 * i) a[j] = 1;
int cnt = 1;
if (n == 2) fout << cnt;
else
{
for (i = 3; i <= n; i += 2)
if (!a[i]) cnt++;
}
fout << cnt;
return 0;
}
