Cod sursa(job #2841075)

Utilizator ciobyCiobanu Vlasie cioby Data 29 ianuarie 2022 11:43:59
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const string name = ("ciur");
ifstream fin(name + ".in");
ofstream fout(name + ".out");


bool ciur[2000005];
int ans = 0;
int n;


void Eratosthenes(int n)
{
	for (int i = 2; i <= n; i++) ciur[i] = 1;
	for (int i = 2; i <= n; i++)
	{
		if (ciur[i])
		{
			ans++;
			for (int j = i + i; j <= n; j += i) ciur[j] = 0;
		}
	}
}

int main()
{
	fin >> n;
	Eratosthenes(n);
	fout << ans;

}