Cod sursa(job #2098170)

Utilizator AndreiTurcasTurcas Andrei AndreiTurcas Data 2 ianuarie 2018 14:54:58
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int n;
bool v[2000005];

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