Cod sursa(job #2152949)

Utilizator AndreiBadescuBadescu Andrei-Octavian AndreiBadescu Data 5 martie 2018 21:20:49
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

#define N 2000001

using namespace std;

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

int n, s;
bool v[N];

void ciur ( int x )
{
	v[0] = v[1] = 1;
	for ( int i = 2; i < x; ++i )
		if ( !v[i] )
			for ( int p = i << 1; p <= n; p += i )
				v[p] = 1;
}

int main()
{
	fin >> n;

	ciur( n );

	for ( int i = 2; i <= n; ++i )
        s += !v[i];

    fout << s;
}