Cod sursa(job #2544324)

Utilizator sipdavSipos David Oliver sipdav Data 11 februarie 2020 22:36:18
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
#include <iostream>
#define DIM (int) (1e9) + 1

using namespace std;

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

bool ciur[DIM];

int main()
{
    int n;
    in>>n;
    int nr = 0;

    for(int i = 2; i <= n; i++)
    {
        if(!ciur[i])
        {
            for(int j = i + i; j <= n; j+=i)
                ciur[j] = 1;
            nr++;
        }
    }
    out<<nr;
    return 0;
}