Cod sursa(job #701397)

Utilizator horeste12Stoianovici Horatiu Andrei horeste12 Data 1 martie 2012 15:37:25
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

int nr,n;
bool v[2000010];

void marcheaza(int x)
{
    int aux=x;
    x+=x;
    while(x<=n)
    {
        v[x]=true;
        x+=aux;
    }
}


int main()
{
    f>>n;
    if(n==1)
    {
        g<<0<<'\n';
        return 0;
    }
    nr=1;
    for(int i=3;i<=n;i+=2)
        if(!v[i])
        {
            marcheaza(i);
            nr++;
        }
    g<<nr<<'\n';
    f.close();g.close();
    return 0;
}