Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <numeric>
- #include <algorithm>
- int main()
- {
- constexpr int max = 30;
- std::vector<int> vec(max - 2);
- std::iota(vec.begin(), vec.end(), 2);
- auto square = std::sqrt(max);
- auto actual = 0;
- do
- {
- vec.erase(std::remove_if(vec.begin() + actual + 1, vec.end(),
- [=](int x){
- return x % vec[actual] == 0;
- }),
- vec.end());
- ++actual;
- } while (vec[actual] <= static_cast<int>(square));
- for (auto val : vec) std::cout << val << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement