Cod sursa(job #875005)

Utilizator Andrei1998Andrei Constantinescu Andrei1998 Data 9 februarie 2013 16:15:15
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>
#include <bitset>
#include <cmath>
//#include <ctime>

using namespace std;
//double start,stop;
bitset <2000005> v;

int main()
{
    ifstream fin("ciur.in");
    ofstream fout("ciur.out");

    int n;
    register int i,j;
    int nr=1;

    fin>>n;
  //  start=clock();
    //int limita=sqrt(n);


    for(i=4;i<=n;i+=2)
        v[i]=1;

    for(i=3;i*i<=n;i+=2)
        if(v[i]==0)
        {
            nr++;
            for(j=i*i;j<=n;j+=i)
                v[j]=1;
        }

    for(;i<=n;i+=2)
        if(v[i]==0)
        {
           nr++;
        }
     //   stop=clock();
    fout<<nr<<'\n';
    //cout<<"A durat "<<(stop-start)/CLOCKS_PER_SEC<<endl;

    fin.close();
    fout.close();
    return 0;
}