Pagini recente » Cod sursa (job #2290154) | Cod sursa (job #1088418) | Cod sursa (job #3131081) | Cod sursa (job #423370) | Cod sursa (job #2259278)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
#define maxsize 2000000
char at1[maxsize / 16];
int n;
int isPrime(int x)
{
if (!(x & 1))
if (x == 2)
return 0 ;
else
return 1 ;
else
return (at1[((x - 3) >> 1) >> 8] & (1 << (((x - 3) >> 1) & 7))) ;
}
void sieve()
{
int i, j;
memset(at1, 0, sizeof(at1)) ;
for (i = 3; i <= n; i += 2)
if (!at1[((i - 3) >> 1) >> 8] & (1 << (((i - 3) >> 1) & 7)))
for (j = i * i ; j <= n ; j += i + i)
at1[((i - 3) >> 1) >> 8] |= (1 << (((i - 3) >> 1) & 7)) ;
}
int main()
{
int cnt = 0;
fin >> n;
sieve();
for (int i = 1; i <= n; i += 2)
{
if (!isPrime(i))
++cnt;
}
fout << cnt << '\n';
return 0;
}