Guest User

Untitled

a guest
Jan 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <cassert>
  5. #include <cstdlib>
  6.  
  7. int allPrimes (unsigned long n) {
  8. std::vector<int> track (n, 0);
  9. int index = 2;
  10. int m = sqrt(n);
  11. while(index < n) {
  12. if (track[index] == 0) {
  13. std::cout << index << std::endl;
  14. int mul = 1;
  15. while ((index <= m) && (n >= (index * ++mul))) {
  16. track[index * mul] = 1;
  17. }
  18. }
  19. index++;
  20. }
  21. }
  22.  
  23. int main() {
  24. int num;
  25. std::cin >> num;
  26. allPrimes(num);
  27. }
  28.  
  29. raise () from /lib64/libc.so.6
  30. abort () from /lib64/libc.so.6
  31. __libc_message () from /lib64/libc.so.6
  32. malloc_printerr () from /lib64/libc.so.6
  33. _int_free () from /lib64/libc.so.6
  34. __gnu_cxx::new_allocator<int>::deallocate
  35. std::_Vector_base<int, std::allocator<int> >::_M_deallocate
  36. std::_Vector_base<int, std::allocator<int> >::~_Vector_base
  37. std::vector<int, std::allocator<int> >::~vector
  38. allPrimes (n=6) at allprimes.cpp:20
  39. main () at allprimes.cpp:26
  40.  
  41. while(index <= n) {
  42. if (track[index] == 0) {
Add Comment
Please, Sign In to add comment