Cod sursa(job #2648140)

Utilizator Calin_IftichiIftichi Albert Ioan Calin Calin_Iftichi Data 8 septembrie 2020 21:34:08
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>

using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n;
bool c[2000001];
void Ciur()
{
    c[2] = 1;
    for(int i = 3; i <= n; i += 2)
        c[i] = 1;
    for(int i = 3; i <= n; i += 2)
    {
        if(c[i] == 1)
            for(int j = i * i; j <= n; j += i)
                c[j] = 0;
    }
}

int main()
{
    int ct = 0;
    fin >> n;
    Ciur();
    for(int i = 1; i <= n; i++)
        if(c[i] == 1)
            ct++;
    fout << ct;
    return 0;
}