Cod sursa(job #2731888)

Utilizator Robys01Robert Sorete Robys01 Data 28 martie 2021 14:50:35
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 2 * 1e6 + 1;
vector <int> a(NMAX);

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