Cod sursa(job #2641347)

Utilizator teofilotopeniTeofil teofilotopeni Data 11 august 2020 10:03:55
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <stdio.h>
using namespace std;

int v[2000001];

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