Cod sursa(job #2569482)

Utilizator gheorghe_cristiGheorghe Florin Cristi gheorghe_cristi Data 4 martie 2020 12:19:23
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <iostream>
#include <fstream>
#include <numeric>

using namespace std;

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

int n;
int fr[2000005];

int main() {
    fin >> n;

    fr[0] = fr[1] = 1;
    for (int i=2;i<=n;++i) {
        if (fr[i] == 0)
            for (int j=i+i;j<=n;j+=i)
                fr[j] = 1;
    }

    fout<<n-accumulate(fr+1, fr+n+1, 0);

}