Cod sursa(job #780788)

Utilizator IliesiDanielDaniel IliesiDaniel Data 21 august 2012 19:24:13
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+1)
				a[j]=1;
		}
	}

	fout<<nr;
}

int main(void)
{
	fin>>n;

	Eratostene();

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