Cod sursa(job #2638564)

Utilizator zarg169Roxana zarg169 Data 28 iulie 2020 19:14:29
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <iostream>
#include <fstream>

using namespace std;
int 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;
}