Cod sursa(job #2672932)

Utilizator tact1m4n3Dicu Tudor Andrei tact1m4n3 Data 15 noiembrie 2020 14:57:11
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include <iostream>
#include <vector>
#include <fstream>

std::ifstream infile("ciur.in");
std::ofstream outfile("ciur.out");

int main()
{
	int n, c = 0;
	infile >> n;

	std::vector<bool> vect(n - 2, true);

	for (int i = 2; i * i < n; i++)
	{
		if (vect[i - 2])
			for (int j = i * i; j < n; j += i)
				vect[j - 2] = 0;
	}

	for (bool v : vect)
		if (v)
			c++;

	outfile << c;
}