Cod sursa(job #3031112)

Utilizator GeorgeAndreiGeorge Andrei Iarca GeorgeAndrei Data 18 martie 2023 18:52:32
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <cstdio>

const int NMAX = 1 << 17;

unsigned char V[NMAX];

int main(void) {
	freopen("ciur.in", "rt", stdin);
	freopen("ciur.out", "wt", stdout);
	int N, i, j, i2, nrprime = 0;

	scanf(" %d", &N);

	for (i = 3; i <= N; i += 2) {
		if (V[i >> 4] & (1 << ((i >> 1) & 7))) continue;
		++nrprime;

		for (j = i + (i2 = i + i); j <= N; j += i2)
			V[j >> 4] |= 1 << ((j >> 1) & 7);
	}

	printf("%d\n", nrprime + 1);

	return 0;
}