Mai intai trebuie sa te autentifici.

Cod sursa(job #2779969)

Utilizator Razvan_GabrielRazvan Gabriel Razvan_Gabriel Data 5 octombrie 2021 16:59:56
Problema Ciurul lui Eratosthenes Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#define L 2000002
#include <fstream>

using namespace std;

int c[L];

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

    int n;
    fin >> n;

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

    for(int i = 2; i <= n; i++)
        if(c[i] == 0)
            np++;

    fout << np;

    return 0;
}