Cod sursa(job #794943)

Utilizator horeste12Stoianovici Horatiu Andrei horeste12 Data 7 octombrie 2012 13:24:45
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 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;
	if(viz[500000])
		;
	for(i = 1; i <= n/2; i++)
	{
		if(!viz[i])
		{
			int x = ((i << 1) + 1) * ((i << 1) + 1);
			while(x < n && x > 0)
			{
				if(x % 2) viz[x >> 1] = 1;
				x += (i << 1) + 1;
			}
		}
		
	}
	printf("%d\n", n - viz.count() - (n-1)/2 - 1);
	return 0;
}