Cod sursa(job #793255)

Utilizator gherghe94Andrei Gherghelau gherghe94 Data 2 octombrie 2012 13:33:42
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <cstdio>
#define Nmax 2000002
using namespace std;
bool ciur[Nmax];
int n;
void citire()
{
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);

    scanf("%d",&n);
    int nr = 0;
    for(int i = 2; i <=n ; ++i)
    {
        if(ciur[i] == false)
        {

            for(int j = i*2 ;j <= n ; j+=i)
                ciur[j] = true;
            nr++;

        }
    }
    printf("%d",nr);
}

int main()
{
    citire();

    return 0;
}