Cod sursa(job #2834424)

Utilizator in-the-loopElliot Anderson in-the-loop Data 16 ianuarie 2022 22:39:43
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <bits/stdc++.h>
#define MAX_N 2000000

using namespace std;

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

int main()
{
    int n, contor = 0;
    fin >> n;
    bitset<MAX_N + 1> ciur;
    ciur[0] = 1;
    ciur[1] = 1;
    for (int i = 2; i <= n; i++)
	if (!ciur[i])
	{
	    contor++;
	    for (int j = i * 2; j <= n; j += i)
		ciur[j] = 1;
	}

    fout << contor;
    return 0;
}