Cod sursa(job #341790)

Utilizator Binary_FireFlorin Pogocsan Binary_Fire Data 19 august 2009 16:00:08
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(c) (int)((c).size())
#define f first
#define s second

#define fin  "ciur.in"
#define fout "ciur.out"

#define NMAX 2000001

int N;
char v[NMAX];

int main()
{
	int i, j, count = 0;
	
	ifstream f(fin);
	ofstream f2(fout);

	f >> N;
	memset(v,0,sizeof(v));
	for ( i = 2; i <= N; ++i )
		if ( !v[i] )
		{
			++count;
			for ( j = 2*i; j <= N; j += i )
				v[j] = 1;
		}

	f2 << count << endl;

	return 0;
}