Cod sursa(job #1202810)

Utilizator AdrianaMAdriana Moisil AdrianaM Data 29 iunie 2014 17:16:31
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#include <vector>
using namespace std;

ifstream is("ciur.in");
ofstream os("ciur.out");

int n, answ = 1;
vector<bool> ok;

int main()
{
    is >> n;
    ok.resize(n + 1);
    for ( int i = 3; i <= n; i += 2 )
    {
        if ( ok[i] )
            continue;
        ++answ;
        for ( int j = i; j <= n; j += i )
            ok[j] = true;
    }
    os << answ;
    is.close();
    os.close();
    return 0;
}