Cod sursa(job #2705330)

Utilizator thvulpeTheodor Vulpe thvulpe Data 12 februarie 2021 13:25:52
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 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])
            for(int j = 2; j <= n / i; j += i)
                v[i * j] = 0;
    for(int i = 2; i <= n; i++)
        if(v[i] == 1) k++;
    fout << k;
    return 0;
}