Pagini recente » Cod sursa (job #1597850) | Cod sursa (job #2339928) | Cod sursa (job #2021506) | Cod sursa (job #131890) | Cod sursa (job #2422832)
#include <fstream>
#include <string>
#include <bitset>
using namespace std;
typedef unsigned long long ULL;
string const inFile = "ciur.in";
string const outFile = "ciur.out";
const unsigned MAX_N = 2 * 1000 * 1000 + 1;
ifstream Read(inFile);
ofstream Write(outFile);
void Sieve(unsigned const length) {
bitset<MAX_N> prime;
unsigned _count = 1;
unsigned i, j;
unsigned increment;
for (i = 3; i <= length; i += 2) {
if (!prime[i]) {
++_count;
if (ULL(i) * ULL(i) > length) {
continue;
}
increment = i << 1;
for (j = i * i; j <= length; j += increment) {
prime.set(j);
}
}
}
Write << _count;
}
int main() {
unsigned n;
Read >> n;
Sieve(n);
return 0;
}