Cod sursa(job #2299623)

Utilizator DariusDCDarius Capolna DariusDC Data 9 decembrie 2018 20:07:48
Problema Ciurul lui Eratosthenes Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMAX = 2000005;

char ciur[NMAX];
int n;

void eratostene()
{
    int nr = 0;
    for (int d=2;d<=n;d++)
    {
        if (ciur[d] == 0)
        {
            nr++;
            int x = d;
            while (x <= n)
            {
                x = x + d;
                ciur[x] = 1;
            }
        }
    }
    fout << nr;
}

int main()
{
    fin >> n;
    eratostene();
    return 0;
}