Cod sursa(job #358441)

Utilizator dorelStoica Razvan-Andrei dorel Data 23 octombrie 2009 08:24:19
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include<cstdio>
#define N 2000000
int n,s=0;
bool v[N];
int ciur (int n) 
{
	v[1]=true;
	for (int d=2 ; d*d<n ; ++d)
	{
		if (v[d]==false)
		{
			for (int i=d*d ; i<n ; i+=d)
			{
				v[i]=true;
			}
		}
	}
	for (int i=2 ; i<n ; ++i) 
	{
		if (v[i]==false)
			++s;
	}
	return s;
}
int main () {
	freopen ("ciur.in","r",stdin);
	freopen ("ciur.out","w",stdout);
	scanf ("%d",&n);
	ciur (n);
	printf ("%d",s);
	return 0;
}