Cod sursa(job #793244)

Utilizator gherghe94Andrei Gherghelau gherghe94 Data 2 octombrie 2012 13:22:21
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <cstdio>
#define Nmax 2000000
using namespace std;
int 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] == 0)
        {
            nr++;
            for(int j = i ;j <= n ; j+=i)
                ciur[j] = 1;
        }
    }
    printf("%d",nr);
}

int main()
{
    citire();

    return 0;
}