Cod sursa(job #2642566)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 16 august 2020 01:12:30
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>

using namespace std;

const int NMAX = 2000005;
bool v[NMAX];


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

int main()
{
    int n, nr, i = 3;
    fin >> n;
    v[1] = v[2] = 1; nr = 1;
    while(i <= n) {
        if(!v[i]) {
            for(int j = 1; j * i <= n; j++) {
                v[j * i] = 1;
            }
            nr++;
        }
        i += 2;
    }
    fout << nr;
    return 0;
}