Cod sursa(job #2863350)

Utilizator Milka69Anastase Luca George Milka69 Data 6 martie 2022 16:30:33
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

#define NMAX 2000005
int N, c[NMAX];

int main()
{
    f >> N;
    c[0] = c[1] = 1;
    for(int i=2;i*i<=N;++i)
        if(c[i] == 0)
            for(int j=2;i*j<=N;++j)
                c[i*j] = 1;

    int k = 0;
    for(int i=2;i<=N;++i)
        if(c[i] == 0)
            ++k;
    g << k;
}