Pagini recente » Cod sursa (job #610434) | Cod sursa (job #201215) | Cod sursa (job #184498) | preONI 2006 | Cod sursa (job #1013463)
// Stive of E.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <bitset>
#include <cstdio>
using namespace std;
void computePrimes( bitset<2000000> arrayOfPrimes, int supperiorBound)
{
int i, j;
for ( i = 1; i <= supperiorBound; ++i )
arrayOfPrimes[i] = 1;
for ( i = 2; i * i < supperiorBound; ++i )
{
if (arrayOfPrimes[i] == 0)
{
for ( j = i * i; j <= supperiorBound; j += i)
arrayOfPrimes[j] = 1;
}
}
}
int main(int argc, char* argv[])
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
bitset<2000000> arrayOfPrimes;
int supperiorBound; cin >> supperiorBound;
computePrimes( arrayOfPrimes, supperiorBound );
long k = 0;
for (int i = 2; i <= supperiorBound; ++i)
if ( arrayOfPrimes[i] == true )
++k;
cout << k;
return 0;
}