Cod sursa(job #3155710)

Utilizator gianiferSpita Alexandru-Mihai gianifer Data 9 octombrie 2023 14:45:45
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <bits/stdc++.h>

#define N_MAX 2000000000

using namespace std;

ifstream fin("ciur.in");

ofstream fout("ciur.out");

bool prim[N_MAX + 1];

int n;
int cnt;

int main()
{
    fin >> n;
    for (int i = 2; i <= n; i++)
    {
        if (!prim[i])
        {
            cnt++;
            for (int j = i + i; j <= n; j += i)
                prim[j] = true;
        }
    }
    fout<<cnt;
}