Cod sursa(job #794925)
| Utilizator | Data | 7 octombrie 2012 13:08:58 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include<cstdio>
#include<bitset>
using namespace std;
int main()
{
bitset<1000010> viz;
viz.reset();
int n;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
if(n == 2)
{
printf("%d\n", 0);
return 0;
}
int i;
for(i = 1; i <= n/2; i++)
{
if(!viz[i])
{
int x = ((i << 1) + 1) * ((i << 1) + 1);
while(x < n)
{
if(x % 2) viz[x >> 1] = 1;
x += (i << 1) + 1;
}
}
}
printf("%d\n", n - viz.count() - (n-1)/2 - 1);
return 0;
}