Cod sursa(job #2715413)

Utilizator crismariuCrismariu Codrin crismariu Data 3 martie 2021 17:38:07
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define test " test "
#define ll long long
#define pii pair<int, int>
#define FASTIO   \
    cin.tie(0);  \
    cout.tie(0); \
    ios_base::sync_with_stdio(0);
#define FILES                      \
    freopen("strmatch.in", "r", stdin); \
    freopen("strmatch.out", "w", stdout);
#define testcase             \
    int T;    \
    cin >> T; \
    while (T--)
#define vec vector<int>
using namespace std;

bool ciur[2000005];
int prim[2000005], ind = 0;

void prec(int n)
{
    ciur[1] = ciur[0] = 1;
    for(int i = 2; i * i <= n; i++)
        for(int j = i * i; j <= n; j += i)
            ciur[j] = 1;
    for(int i = 2; i <= n; i++)
        prim[i] += prim[i - 1] + !ciur[i];
}


signed main()
{
    FASTIO;
    int n;
    cin >> n;
    prec(n);
    cout << prim[n];
}