Cod sursa(job #2705332)

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