Cod sursa(job #3125425)

Utilizator cristiWTCristi Tanase cristiWT Data 3 mai 2023 08:58:30
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

const int NMAX = 2e6 + 10, mod = 1e9 + 7;
int n, cnt;
bool prime[NMAX];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);

    cin >> n;
    fill(prime, prime + NMAX, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i <= n; i++)
        if (prime[i]) {
            cnt++;
            for (int j = i * i; j <= n; j += i)
                prime[j] = false;
        }
    cout << cnt;
}