Pagini recente » Cod sursa (job #1073357) | Cod sursa (job #3263847) | Cod sursa (job #3031915) | Cod sursa (job #1201702) | Cod sursa (job #2569393)
#include <fstream>
#include <bitset>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
const int N = 2e6 + 6;
bitset<N>ciur;
int main()
{
int n, ans;
in >> n;
ans = 2;
for(int i = 5; i <= n; i += 6)
{
if(ciur[i] == 0)
{
ans++;
if(1ll * i * i <= n)
for(int j = i * i; j <= n; j += 2 * i)
ciur[j] = 1;
}
if(ciur[i + 2] == 0 && i + 2 <= n)
{
ans++;
int nr = i + 2;
if(1ll * nr * nr <= n)
for(int j = nr * nr; j <= n; j += 2*nr)
ciur[j] = 1;
}
}
if(n == 2) out << 1;
else if(n < 5) out << 2;
else out << ans;
return 0;
}