Cod sursa(job #1559786)

Utilizator roxannemafteiuMafteiu-Scai Roxana roxannemafteiu Data 31 decembrie 2015 16:01:50
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;

int upperBound;

void readUpperBound()
{
    ifstream fin("ciur.in");

    fin >> upperBound;

    fin.close();
}

int sieveOfEratosthenes()
{
    int numberOfPrimeValues = 1;
    bool numbers[upperBound];

    for(int i = 3; i <= upperBound; i += 2)
    {
        if(!numbers[i])
        {
            ++numberOfPrimeValues;

            for(int j = i * 2; j <= upperBound; j += i)
                numbers[j] = true;
        }
    }

    return numberOfPrimeValues;
}

void printSolution()
{
    ofstream fout("ciur.out");

    fout << sieveOfEratosthenes();

    fout.close();
}

int main()
{
    readUpperBound();
    printSolution();

    return 0;
}