Cod sursa(job #1828406)

Utilizator doroftei1999Doroftei Andrei doroftei1999 Data 13 decembrie 2016 11:30:58
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>

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

int main() {
    int k = 0, n;
    in >> n;
    bool v[n + 1];
    for (int i = 2; i <= n; i++)
        v[i] = true;
    for (int i = 2; i <= n; i++)
        if (v[i]) {
            k++;
            for (int j = i + i; j <= n; j += i)
                v[j] = false;
        }
    out << k;
    return 0;
}