Cod sursa(job #2469195)

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

#define ARR_MAX 100005

using namespace std;

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

int k, sol;
char check[ARR_MAX];

int main()
{
    fin >> k;

    for(int i = 2; i <= k; i++)
        check[i] = 1;

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

            for(int j = 2*i; j <= k; j += i)
                check[j] = 0;
        }

    fout << sol;
}