Cod sursa(job #2723419)

Utilizator dcovDarius Covaciu dcov Data 14 martie 2021 00:31:47
Problema Ciurul lui Eratosthenes Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

int n,a[2000005],nr=0;

void cit()
{
    f>>n;

    for(int i=2;i<=n;i++)
        a[i]=i;
}

void nrprime()
{
    for(int i=2;i<=n;i++)
    {
        if(a[i])
        {
            for(int j=i+i;j<=n;j+=i)
                a[j]=0;

            nr++;
        }
    }
}

int main()
{
    cit();

    nrprime();

    g<<nr;

    return 0;
}