Cod sursa(job #1757675)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 15 septembrie 2016 17:33:07
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include<fstream>
using namespace std;
ifstream fi("ciur.in");
ofstream fo("ciur.out");
int n;
bool E[2000001];

int e(int n)
{
    int nr=0,i,j;
    for(i=1; ((i*i)<<1)+(i<<1)<=n; i++)
    {
        if(E[i]==0)
        {
            for (j=((i*i)<<1)+(i<<1); (j<<1)+1<=n; j+=(i<<1)+1)
            {
                E[j]=1;
            }
        }
    }
    for(i=1; 2*i+1<=n; i++)
        if(E[i]==0)
            nr++;
    return nr+1;
}

int main()
{
    fi>>n;
    fo<<e(n)<<"\n";
    fi.close();
    fo.close();
    return 0;
}