Cod sursa(job #627467)

Utilizator the_snyper06FMI - ALexandru Mihai the_snyper06 Data 30 octombrie 2011 00:33:18
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include<cstdio>
#include<vector>

using namespace std;

int n;

// 2.000.000.000
vector <bool>v;

int main()
{
	int i, k, x;
	
	freopen("ciur.in", "r", stdin);
	freopen("ciur.out", "w", stdout);
	
	scanf("%d", &n);
	
	for(i = 0; i <= n; i++) v.push_back(true);
	for(i = 2; i <= n; i++)
	{
		if(v[i])
		{
			k = 2;
			x = i * k;
			while(x <= n)
			{
				v[x] = false;
				k++;
				x = i * k;
			}
		}
	}
	
	int k = 0;
	for(i = 2; i <= n; i++)
		if(v[i]) k++;
	printf("%d\n", k);
	
	return 0;
}