Cod sursa(job #664428)

Utilizator feelshiftFeelshift feelshift Data 20 ianuarie 2012 08:44:42
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 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()
{
	int stop = length / 2;
	for(int i=3;i<=stop;i+=2)
		for(int k=i+i;k<=length;k=k+(i << 1))
			numbers[k] = true;
}