Cod sursa(job #1452700)

Utilizator GilgodRobert B Gilgod Data 21 iunie 2015 17:35:01
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
#include <bitset>

const char IN[] = "ciur.in", OUT[] = "ciur.out";
const int NMAX = 2000003;

using namespace std;
int N;
bitset<NMAX> notPrime;

inline void read_data() {
	fscanf(fopen(IN, "r"), "%d", &N);
}

int count() {
	int cnt = 0;
	for (int p = 2; p <= N; ++p) {
		if (!notPrime[p]) {
			++cnt;
			for (int j = p + p; j <= N; j += p) 
				notPrime[j] = true;
		}
	}
	return cnt;
}

int main() {
	read_data();
	fprintf(fopen(OUT, "w"), "%d\n", count());
	return 0;
}