Cod sursa(job #1500715)

Utilizator shpincCandrea Laurentiu Vasile shpinc Data 12 octombrie 2015 16:48:50
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

const int NMax =  2e6 + 5;

int k;
int Prime[NMax];
bool viz[NMax];

void ciur(int n){

    k = 1;
    for(int i = 3; i <= n; i = i + 2){
    if(viz[i] == 0){
        k++;
        Prime[k] = i;
        for(int j = 3 * i; j <= n; j = j + (2*i)){
            viz[j]=1;

            }
        }

    }


}

int main()
{
    int n,ans=0;
    f>>n;
    ciur(n);
    g<<k;


    return 0;
}