Cod sursa(job #2572959)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 5 martie 2020 15:09:36
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

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

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

const int N = 2e6 + 5;

vector < int > prime;

bool f[N];

void sieve(int n)
{
    for(int i = 2; i < n; ++i) {
        if(f[i] == false) prime.push_back(i);
        for(int j = 0; j < prime.size() && i * prime[j] < n; ++j) {
            f[i * prime[j]] = true;
            if(i % prime[j] == 0) break;
        }
    }
}

int main()
{
    usain_bolt();

    int n;

    fin >> n;
    sieve(n);
    fout << prime.size();
    return 0;
}