Cod sursa(job #2591955)

Utilizator mihai03Mihai Grigore mihai03 Data 31 martie 2020 18:48:19
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int maxx = 2000005;
int n;
bool notPrime[maxx];
void Read()
{
    fin >> n;
    fin.close();
}
void Solve()
{
    int cnt = 0;
    for(int i = 2; i <= n; i++)
    {
        if(notPrime[i] == 0)
        {
            ++cnt;
            for(int j = i * 2; j <= n; j += i)
            {
                notPrime[j] = 1;
            }
        }
    }
    fout << cnt;
    fout.close();
}
int main()
{
    Read();
    Solve();
    return 0;
}