Cod sursa(job #1779427)

Utilizator AdrianaMAdriana Moisil AdrianaM Data 15 octombrie 2016 12:15:51
Problema Ciurul lui Eratosthenes Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>
#include <vector>
using namespace std;

const string fis = "ciur";
ifstream is(fis + ".in");
ofstream os(fis + ".out");

using VI = vector<int>;
using VS = vector<short>;
using VVI = vector<VI>;

int n, answ = 1;
VS c;

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