Cod sursa(job #2293927)

Utilizator TooHappyMarchitan Teodor TooHappy Data 1 decembrie 2018 18:34:18
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <bits/stdc++.h>
 
using namespace std;

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

vector< bool > isPrime(2e6 + 10, true);

int main() {
    ios::sync_with_stdio(false); in.tie(0); out.tie(0);

    int n; in >> n;

    for(int i = 4; i <= n; i += 2) {
        isPrime[i] = false;
    }

    int ans = 1;
    for(int i = 3; i <= n; i += 2) {
        if(isPrime[i]) {
            ++ans;

            for(int j = i; j <= n; j += i) {
                isPrime[j] = false;
            }
        }
    }

    out << ans << "\n";
 
    in.close(); out.close();
 
    return 0;
}