Cod sursa(job #359040)

Utilizator MythGhiorghe Mihaita Myth Data 25 octombrie 2009 15:28:03
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.34 kb
#include <iostream>
#include <fstream>
#define max 2000000

using namespace std;

int main() {
	int n, i, j;
	char c[max];

	ifstream f("ciur.in");
	ofstream g("ciur.out");
	f>>n;
	for (i=2; i<n; ++i)
		c[i]=1;
	for (i=2; i<n; ++i)
		if (c[i]) 
			for (j=2; i*j<n; ++j)
				c[i*j]=0;
	j=0;
	for (i=2; i<n; ++i)
		if (c[i])
			++j;
	g<<j;
	return 0;
}