Cod sursa(job #2469688)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 7 octombrie 2019 20:56:35
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>

#define ARR_MAX 2000005

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;
}