Cod sursa(job #2638581)

Utilizator zarg169Roxana zarg169 Data 28 iulie 2020 20:44:51
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#include <fstream>

using namespace std;
bool notPrime[2000001];

int main()
{
    ifstream fin("ciur.in");
    ofstream fout("ciur.out");

    int n, c = 0;
    fin >> n;
    notPrime[0] = notPrime[1] = true;
    for (int i = 2; i <= n; ++i) {
        if (!notPrime[i]) {
            c += 1;
            for (int j = 2 * i; j <= n; j += i) {
                notPrime[j] = true;
            }
        }
    }

    fout << c;
    return 0;
}