Cod sursa(job #3241935)

Utilizator CondoracheAlexandruCondorache Alexandru CondoracheAlexandru Data 6 septembrie 2024 12:51:17
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define all(a) (a).begin(),(a).end()
using namespace std;
const int maxn = 1e5 + 5;

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

ll sieve(ll n) {
    vector<ll> prime(n + 1, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (ll i = 2; i * i <= n; i++) {
        if (prime[i]) {
            for (ll j = i * i; j <= n; j += i) {
                prime[j] = 0;
            }
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n + 1; i++) {
        ans += prime[i];
    }
    return ans;
}

void solve() {
    ll n;
    fin >> n;
    int ans = sieve(n);
    fout << ans << endl;
}
 
int main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}