Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <numeric>
  5. #include <algorithm>
  6.  
  7.  
  8. int main()
  9. {
  10. constexpr int max = 30;
  11. std::vector<int> vec(max - 2);
  12. std::iota(vec.begin(), vec.end(), 2);
  13.  
  14. auto square = std::sqrt(max);
  15. auto actual = 0;
  16. do
  17. {
  18. vec.erase(std::remove_if(vec.begin() + actual + 1, vec.end(),
  19. [=](int x){
  20. return x % vec[actual] == 0;
  21. }),
  22. vec.end());
  23. ++actual;
  24. } while (vec[actual] <= static_cast<int>(square));
  25.  
  26. for (auto val : vec) std::cout << val << '\n';
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement