Cod sursa(job #2705314)

Utilizator thvulpeTheodor Vulpe thvulpe Data 12 februarie 2021 13:01:35
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, k, v[2000005];

int main(){
    fin >> n;
    for(int i = 2; i <= n; i++)
        v[i] = 1;
    for(int i = 2; i * i <= n; i++){
        if(v[i] == 1){
            for(int j = 2 * i; j <= n; j += i){
                v[j] = 0;
            }
        }
    }
    for(int i = 2; i <= n; i++)
        if(v[i] == 1) k++;
    fout << k;
    return 0;
}