Cod sursa(job #2068220)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 17 noiembrie 2017 13:27:52
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <fstream>
#include <bitset>

using namespace std;

int n, i, j, c;
bitset<2000003> p;

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

int main()
{
    in >> n;
    for(i = 2; i*i <= n; i++) {
        if(p.test(i) == 0) for(j = i*i; j <= n; j = j+i) p.set(j, 1);
    }

    for(i = 2; i <= n; i++) if(p.test(i) == 0) c++;

    out << c;
    return 0;
}