Cod sursa(job #1052439)

Utilizator torckySuciu Victor torcky Data 11 decembrie 2013 12:11:26
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <cstdio>
#include <cmath>
using namespace std;
bool c[2000001];
int ciur(int n){
    int lim,gogu=0;
    c[0]=c[1]=1;
    lim=(int)sqrt((double)n);
    for(int i=4;i<=n;i=i+2){
        c[i]=1;
    }
    for(int i=3;i<=lim;i=i+2){
        if(c[i]==0){
            for(int j=2*i;j<=n;j=j+i){
                c[i]=1;
            }
        }
    }
    for(int i=0;i<=n;i++){
        if(c[i]==0)
            gogu++;
    }
    return gogu;
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d ",ciur(n));
    return 0;
}