Cod sursa(job #2339842)

Utilizator dahaandreiDaha Andrei Codrin dahaandrei Data 9 februarie 2019 13:56:27
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

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

const int MAXN = 2e6;
int n, cnt;

bool c[MAXN + 1];
void ciur() {
	c[0] = c[1] = 1;
	++ cnt;
	for (int i = 4; i <= n; i += 2) c[i] = 1;

	for (int i = 3; i <= n; i += 2) {
		if (!c[i]) {
			++ cnt;
			for (int j = i + i; j <= n; j += i) {
				c[j] = 1;
			}
		}
	}
}

int main() {
	in >> n;
	ciur();
	out << cnt;
	return 0;
}