daria-grebneva / OOP

0 stars 0 forks source link

Замечания по генератору простых чисел #14

Open alexey-malov opened 6 years ago

alexey-malov commented 6 years ago
1>c:\teaching\2018\oop\grebneva\oop\lr_02\primenumbers_test\main.cpp(17): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
vector<bool> GetEratosthenesSieve(int upperBound)
{
    vector<bool> numbers(upperBound + 1, true);
    for (int i = 2; i * i <= upperBound; ++i)
    {
        if (numbers[i])
        {
            for (int j = i * i; j <= upperBound; j += i)
            {
                numbers[j] = false;
            }
        }
    }
    return numbers;
}

set<int> GetPrimeNumbersSet(int upperBound)
{
    set<int> primes;

    auto numbers = GetEratosthenesSieve(upperBound);

    for (int i = 2; i < numbers.size(); i++)
    {
        if (numbers[i])
        {
            primes.insert(primes.end(), static_cast<int>(i));
        }
    }

    return primes;
}