Cod sursa(job #786744)

Utilizator Mihai22eMihai Ionut Enache Mihai22e Data 11 septembrie 2012 23:20:48
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include<stdio.h>
#include<fstream>

using namespace std;

#define MAXN 2000002

char v[ MAXN ];
int n, i, j, res;

int main()
{
	ifstream f("ciur.in");
	
	f >> n;
	
	f.close();
	
	for(i = 2; i <= n; ++i)
		if(!v[i])
			for(++res, j = i + i; j <= n; j += i)
				v[j] = 1;
			
	FILE *g = fopen("ciur.out", "w");

	fprintf(g, "%d\n", res);
	
	fclose(g);
	
	return 0;
}