Cod sursa(job #1407453)
Utilizator | Petenchea Alexandru alex_unix | Data | 29 martie 2015 18:46:13 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#include <bitset>
const int MAX_SIZE(1000001);
std::bitset<MAX_SIZE> Mark;
int main (void)
{
std::ifstream input("ciur.in");
int n;
input >> n;
input.close();
n /= 2;
int counter(1);
for (int i(1) ; i <= n ; ++i)
if (!Mark[i])
{
++counter;
for (int j(i), k(2 * i) ; j <= n ; j += k)
Mark[j] = true;
}
std::ofstream output("ciur.out");
output << counter << '\n';
output.close();
return 0;
}