Cod sursa(job #2469173)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 6 octombrie 2019 16:23:04
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 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;

int Ciur(int x)
{
    int sol = 1;

    for(int i = 1; ((i * i) << 1) + (i << 1) <= x; i += 1)
        if(!check[i]){
            for(int j = ((i * i) << 1) + (i << 1); (j << 1) + 1 <= x; j += (i << 1) + 1)
                check[j] = 1;
        }

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

    return sol;
}

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