Cod sursa(job #2469158)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 6 octombrie 2019 16:04:37
Problema Ciurul lui Eratosthenes Scor 0
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;

int 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; i < x; j += i)
                check[j] = 0;

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

    return sol;
}

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