Cod sursa(job #2641397)

Utilizator teofilotopeniTeofil teofilotopeni Data 11 august 2020 11:52:17
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <stdio.h>
using namespace std;

int v[200000010];

int main()
{
	freopen("ciur.in", "r", stdin);
	freopen("ciur.out", "w", stdout);
	int n, tot = 1, i, j;
	scanf("%d", &n);
	for (i = 1; i <= n / 2; i++) v[i] = 1;
	for (i = 3; i <= n; i += 2) {
		if (v[i / 2]) {
			tot++;
			for (int j = 3 * i; j <= n; j += 2 * i) v[j / 2] = 0;
		}
	}
	printf("%d", tot);
	return 0;
}