Cod sursa(job #1407574)
Utilizator | Petenchea Alexandru alex_unix | Data | 29 martie 2015 19:06:03 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 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();
int counter(1);
for (int i(1), end(n / 2 - (n % 2 ? 0 : 1)) ; i <= end ; ++i)
if (!Mark[i])
{
++counter;
for (int j(2 * i + 1), k(2 * j) ; j <= n ; j += k)
Mark[j / 2] = true;
}
std::ofstream output("ciur.out");
output << counter << '\n';
output.close();
return 0;
}