Cod sursa(job #781263)

Utilizator IliesiDanielDaniel IliesiDaniel Data 24 august 2012 00:01:06
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
#define Elemente 1000005

using namespace std;

ifstream fin("ciur.in");
ofstream fout("ciur.out ");

unsigned long int n, nr=1, a[Elemente];

void Eratostene(void)
{
	unsigned long int i, j;

	for(i=1; i+i+1<=n; ++i)
	{
		if(a[i]==0)
		{
			nr++;

			for(j=i+i+i+1; j+j+1<=n; j+=i+i+1)
				a[j]=1;
		}
	}
}

int main(void)
{
	fin>>n;

	Eratostene();

	fout<<nr;

	fin.close();
	fout.close();
	return 0;
}