Cod sursa(job #664424)

Utilizator feelshiftFeelshift feelshift Data 20 ianuarie 2012 08:31:32
Problema Ciurul lui Eratosthenes Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
// http://infoarena.ro/problema/ciur
#include <fstream>
using namespace std;

const int MAXSIZE = 2000001;

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

int length;
bool numbers[MAXSIZE];

void eratosthenes();

int main()
{
	in >> length;
	in.close();

	eratosthenes();

	int count = 0;
	for(int i=3;i<=length;i+=2)
		if(!numbers[i])
			count++;

	out << ++count << "\n";
	out.close();

	return (0);
}

void eratosthenes()
{
	for(int i=3;i<=length;i+=2)
		for(int k=i+i;k<=length;k=k+i)
			numbers[k] = true;
}