Cod sursa(job #2779966)

Utilizator Razvan_GabrielRazvan Gabriel Razvan_Gabriel Data 5 octombrie 2021 16:49:53
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#define L 2000000
#include <fstream>

using namespace std;

char c[L];

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

    int n;
    fin >> n;

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

    fout << np;

    return 0;
}