Cod sursa(job #2568630)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 4 martie 2020 08:50:31
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda r3capitusulare Marime 0.36 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("ciur.in");
ofstream fout("ciur.out");

const int DIM = 2e6 + 1;

bitset <DIM> vis;

main()
{
	int n;
	fin >> n;
	
	int cnt = 1;
	
	for(int i = 3; i <= n; i += 2)
		if(!vis[i])
		{
			++cnt;
			
			if(i * 1LL * i <= n)
				for(int j = i * i; j <= n; j += 2 * i)
					vis[j] = true;
		}
	
	fout << cnt << '\n';
}