Cod sursa(job #1988504)
Utilizator | Data | 3 iunie 2017 10:54:17 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");ofstream fout("ciur.out");
const int Nmax=2000001;
bitset<Nmax>ciur;
int main()
{
ciur[0]=ciur[1]=1;
for(int i=3;i*i<=Nmax;i+=2){
if(ciur[i]==0)
for(int j=i*i;j<=Nmax;j=j+2*i){
ciur[j]=1;
}
}
int n,cnt=0;
fin>>n;
for(int i=2;i<=n;i++)
if(ciur[i]==0)
cnt++;
fout<<cnt;
return 0;
}