Pagini recente » Cod sursa (job #1619376) | Cod sursa (job #461345) | Cod sursa (job #3157069) | Cod sursa (job #1699375) | Cod sursa (job #2765444)
#include <bits/stdc++.h>
using namespace std;
inline void Open(const string Name) {
#ifndef ONLINE_JUDGE
(void)!freopen((Name + ".in").c_str(), "r", stdin);
(void)!freopen((Name + ".out").c_str(), "w", stdout);
#endif
}
int prime[31250];
int N;
bool ifnotPrime(int x) {
return (prime[x / 64] & (1 << ((x >> 1) & 31)));
}
void makeComposite(int x) {
prime[x / 64] |= (1 << ((x >> 1) & 31));
}
void bitwiseSieve() {
for(long long i = 3;i * i <= N;i += 2)
if(!ifnotPrime((int)i)) {
for(long long j = i * i, k = i << 1LL;j <= N;j += k)
makeComposite((int)j);
}
int ans = 1;
for(int i = 3;i <= N;i += 2)
if(!ifnotPrime(i)) ans++;
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Open("ciur");
cin >> N;
if(N == 1) {
cout << 0;
return 0;
}
bitwiseSieve();
}