Cod sursa(job #2621802)

Utilizator filipasvladVlad Filipas filipasvlad Data 30 mai 2020 19:42:17
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

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

int n;
bool v[2000005];

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