Cod sursa(job #2377094)
Utilizator | Carp Rafael Nope | Data | 8 martie 2019 21:40:59 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
bitset<2000000> a;
int n;
int main()
{
int i , j , cnt;
n = 2000000;
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] == 0)
for (j = i * i ; j <= n ; j += 2 * i)
a[j] = 1;
fin >> n;
cnt = 0;
for (i = 2 ; i <= n ; i++)
if (a[i] == 0) cnt++;
fout << cnt << "\n";
return 0;
}