Mai intai trebuie sa te autentifici.

Cod sursa(job #2543779)

Utilizator MarcGrecMarc Grec MarcGrec Data 11 februarie 2020 15:18:30
Problema Ciurul lui Eratosthenes Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#define MAX_N 1000000

#include <fstream>
#include <bitset>
using namespace std;

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

int n;
bitset<MAX_N + 1> P;

int main()
{
	fin >> n;
	P.set();
	P[0] = P[1] = false;
	
	for (int i = 2; (i * i) <= n; ++i)
	{
		if (P[i])
		{
			for (int j = 2; (i * j) <= n; ++j)
			{
				P[i * j] = false;
			}
		}
	}
	
	int rasp = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (P[i]) { ++rasp; }
	}
	
	fout << rasp;
	
	fin.close();
	fout.close();
	return 0;
}