Cod sursa(job #1678822)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 7 aprilie 2016 15:44:52
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <cstdio>
bool v[2000023];
int n;
int main()
{
    freopen ("ciur.in","r",stdin);
    freopen ("ciur.out","w",stdout);
    scanf("%d",&n);
    int ct=0;
    v[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(v[i]==0)
        {
                ++ct;
                for(int j=2*i;j<=n;j+=i) v[j]=1;
        }
    }
    printf("%d\n",ct);
}