Cod sursa(job #1242558)

Utilizator radudorosRadu Doros radudoros Data 14 octombrie 2014 18:00:19
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;

ifstream fin("ciur.in");
ofstream fout("ciur.out");
bitset<2000001> v;

int main()
{

	long long n;
	fin >> n;
	int nr = 0;
	if (n >= 2)
		nr++;
	for (int i = 1; (i << 1) + 1 <= n; i += 1)
	{
		if (v[i] == 0)
		{
			nr++;
			for (int j = 3 * i + 1; (j << 1) + 1 <= n; j += (i << 1) + 1)
			{
				v[j] = 1;
			}
		}
	}
	/*if (n >= 2)
		fout << "2 ";
	for (int i = 1; (i<<1)+1<=n ; i++)
	{
		if (v[i] == 0)
		fout << (i << 1) + 1 << ' ';

	}
	*/
	fout << nr;
}