Cod sursa(job #1052451)

Utilizator torckySuciu Victor torcky Data 11 decembrie 2013 12:25:32
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 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[j]=1;
            }
        }
    }
    for(int i=0;i<=n;i++){
        if(c[i]==0)
            gogu++;
    }
    return gogu;
}
int main()
{
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);
    int n;
    scanf("%d",&n);
    printf("%d ",ciur(n));
    return 0;
}