Cod sursa(job #1315858)

Utilizator cernat.catallinFMI Cernat Catalin Stefan cernat.catallin Data 13 ianuarie 2015 10:48:56
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
#include <iostream>
#include <bitset>
using namespace std;

typedef long long unsigned int uint64;


const int Nmax  = 2000005;

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

bitset<Nmax> v;

uint64 ciur(uint64 n){
	uint64 total = 0;
	for (uint64 i = 2; i * i <= n; ++i)
		if (!v[i])
			for (uint64 j = i * i; j <= n; j += i)
				v[j] = 1;
	for (uint64 i = 2; i <= n; ++i)
		if (!v[i]) ++total;
	return total;
}

int main(){
	int n;
	in >> n;
	out << ciur(n);

	return 0;
}