Cod sursa(job #2449847)

Utilizator george.andronacheAndronache George-Codrin george.andronache Data 20 august 2019 20:47:26
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");

int n,nr;
const int Nmax=2000005;
bool v[Nmax];
int main()
{
    fin>>n;
    nr = 1;
    for(int i=3;i<=n;i+= 2)
    {
        if(!v[i])
        {
            nr++;
            for(int j=3*i;j<=n;j+=2*i)
            {
                v[j]=1;
            }
        }
    }

    fout<<nr;
    return 0;
}