Cod sursa(job #1171866)

Utilizator EhtRalpmetFMI Ardei Claudiu-Alexandru EhtRalpmet Data 16 aprilie 2014 15:10:28
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<fstream>

using namespace std;
ifstream cin("ciur.in");
ofstream cout("ciur.out");

long long k,i,j,n;
bool bl[2000010];

int main() {
    cin>>n;
    i=2;
    while(i<=n){
        while(bl[i]){
            i++;
        }
        if(i>n){
            break;
        }
        bl[i]=1;
        k++;
        for(j=i*i;j<=n;j+=i){
            bl[j]=1;
        }
    }
    cout<<k;
    return 0;
}