Cod sursa(job #2641376)

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

int v[200000005];

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