Cod sursa(job #2641345)

Utilizator teofilotopeniTeofil teofilotopeni Data 11 august 2020 09:55:25
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <stdio.h>
#include <fstream>
#include <iostream>
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;
}