Cod sursa(job #2469181)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 6 octombrie 2019 16:26:45
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>  //for ifstream, ofstream
#include <cmath>    //for sqrt(x)
#include <bitset>   //for bitset<>

#define ARR_MAX 100005

using namespace std;

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

bitset<ARR_MAX> check; //boolean array made of only 0 and 1
int k; //the initial number

int main()
{
    fin >> k;

    int sol = 1;

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

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

    fout << sol;
}