Cod sursa(job #1883257)

Utilizator Alex18maiAlex Enache Alex18mai Data 17 februarie 2017 20:38:18
Problema Ciurul lui Eratosthenes Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>

using namespace std;

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

const int MAX=2e6;

bool KillMyselfWithASpoon [MAX];

int main()
{
    int n;
    cin>>n;
    int S=0;
    for (int i=2; i<=n; i++){
        if (KillMyselfWithASpoon [i]==0) {
            for (int j=i+i; j<=n; j+=i){
                KillMyselfWithASpoon [j]=1;
            }
            S=S+1;
        }

    }
    cout<<S;

    return 0;
}