Cod sursa(job #3343446)

Utilizator FistfullOfDollar059Andrei Marin Popa FistfullOfDollar059 Data 27 februarie 2026 14:11:53
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;
# define ll long long


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ifstream cin("ciur.in");
    ofstream cout("ciur.out");

    int n;
    cin>>n;
    vector<bool> isPrime(n+1,1);

    for(int i = 2; i*i <= n; i++){
        if(isPrime[i]){
            for(int j = i*i; j <= n; j+=i){
                isPrime[j] = 0;
            }
        }
    }
    int ans = 0;
    for(int i = 2; i < n; i++){
        if(isPrime[i]){
            ans++;
        }
    }

    cout<<ans;








    return 0;
}