Cod sursa(job #1723241)
| Utilizator | Data | 30 iunie 2016 10:15:31 | |
|---|---|---|---|
| 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<2000005>a;
int n;
int Ciur(int n)
{
int i, j;
for(i = 4; i <= n; i += 2)
a[i] = 1;
for(i = 3; i <= n; i++)
if(a[i] == 0)
for(j = 2 * i; j <= n; j += i)
a[j] = 1;
int cnt = 0;
for(i = 2; i <= n; i++)
if(a[i] == 0)
cnt++;
return cnt;
}
int main()
{
ifstream f("ciur.in");
f >> n;
f.close();
ofstream g("ciur.out");
g << Ciur(n) << "\n";
g.close();
return 0;
}
