Cod sursa(job #2469164)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 6 octombrie 2019 16:09:44
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
#include <cmath>
#include <bitset>

#define ARR_MAX 100005

using namespace std;

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

bitset<ARR_MAX> check;
int k, sol;

void Ciur(int x)
{
    for(int i = 2; i < x; i++)
        check[i] = 1;

    for(int i = 2; i <= sqrt(x); i++)
        if(check[i])
            for(int j = i * i; j < x; j += i)
                check[j] = 0;

    for(int i = 2; i < x; i++)
        if(check[i])
            sol++;

}

int main()
{
    fin >> k;
    Ciur(k);
    fout << sol;
}