Cod sursa(job #2224823)

Utilizator andreisontea01Andrei Sontea andreisontea01 Data 25 iulie 2018 11:44:44
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;

const int MAXN = 2000005;

bool ciur[MAXN];
int val[MAXN];

int main()
{
    ifstream fin("ciur.in");
    ofstream fout("ciur.out");
    int n;
    fin >> n;
    for(int i = 4; i <= n; i += 2)
        ciur[i] = 1;
    int len = 0;
    val[++len] = 2;
    for(int i = 3; i <= n; i += 2){
        if(!ciur[i]){
            val[++len] = i;
            for(int j = i * i; j <= n; j += 2 * i)
                ciur[j] = 1;
        }
    }
    fout << len;
    return 0;
}