Cod sursa(job #2727665)

Utilizator vansJos da pa perete vans Data 22 martie 2021 12:07:11
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <iostream>

using namespace std;

const int CMAX = 2e6;

int n, ans;
bool c[CMAX + 1];

int main()
{
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 2; i <= n; ++i)
        if(!c[i]) {
            ++ans;
            for(int j = 2 * i; j <= n; j += i) c[j] = 1;
        }
    printf("%d", ans);
    return 0;
}