Cod sursa(job #2641357)

Utilizator teofilotopeniTeofil teofilotopeni Data 11 august 2020 10:59:23
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
using namespace std;

int v[2000005];

int main()
{
	ifstream in ("ciur.in");
	ofstream out ("ciur.out");
	int n, tot = 0, i;
	in >> n;
	for (i = 3; i < n; i += 2) v[i] = 1;
	for (i = 2; i <= n; i++) {
        if (v[i] && i % 2) {
            tot++;
            for (int j = 2 * i; j <= n; j += i) v[j] = 0;
        }
        else if (i == 2) tot++;
	}
	out << tot;
	return 0;
}