Pagini recente » Cod sursa (job #284768) | Cod sursa (job #1232649) | Cod sursa (job #2169205) | Cod sursa (job #1713568) | Cod sursa (job #1013457)
// Stive of E.cpp : Defines the entry point for the console application.
//
#include <IOSTREAM>
#include <cstdio>
using namespace std;
void computePrimes( bool *arrayOfPrimes, int supperiorBound)
{
int i, j;
for ( i = 1; i <= supperiorBound; ++i )
arrayOfPrimes[i] = true;
for ( i = 2; i * i < supperiorBound; ++i )
{
if (arrayOfPrimes[i] == true)
{
for ( j = i * i; j <= supperiorBound; j += i)
arrayOfPrimes[j] = false;
}
}
}
int main(int argc, char* argv[])
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
bool *arrayOfPrimes;
int supperiorBound; cin >> supperiorBound;
arrayOfPrimes = new bool [supperiorBound + 1];
computePrimes( arrayOfPrimes, supperiorBound );
long k = 0;
for (int i = 2; i <= supperiorBound; ++i)
if ( arrayOfPrimes[i] == true )
++k;
cout << k;
delete [] arrayOfPrimes;
return 0;
}