Cod sursa(job #1756797)

Utilizator theodor.moroianuTheodor Moroianu theodor.moroianu Data 13 septembrie 2016 17:36:59
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
using namespace std;
bool v[2000000];
 
int main()
{
    ifstream in ("ciur.in");
    ofstream out ("ciur.out");
    int n;
    in >> n;
    for (int i = 2; i * i <= n; i++){
        if (! v[i]){
            for (int j = i * i; j <= n; j += i)
                v[j] = true;
        }
    }
    int t = 0;
    for (int i = 2; i < n; i++)
        if(!v[i])
            t++;
    out << t;
    return 0;
}