Cod sursa(job #2197725)
Utilizator | Data | 22 aprilie 2018 19:40:34 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#include <bitset>
#define NUM 2000005
using namespace std;
bitset<NUM> ciur;
int n, total;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f >> n;
for(int i = 2; i <= n; ++i)
{
if(!ciur[i])
{
total++;
for(int d = i * i; d <= n; d += i)
ciur[d] = 1;
}
}
g << total;
f.close();
g.close();
}