Cod sursa(job #1846661)
Utilizator | Data | 13 ianuarie 2017 21:17:00 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
bitset<1000010> b;
int n,m,i,j,k;
int main()
{
f>>n;
if(n%2==0)
n--;
m=(n-1)/2;
for(i=1,j=3;j*j<=n;i++,j+=2)
if(!b[i])
{
for(k=2*i*i+2*i;k<=m;k+=j)
b[k]=1;
}
g<<m-b.count()+1;
return 0;
}