Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4.  
  5. std::string get_concatenated_primes()
  6. {
  7. unsigned int base, test, cap=1000, prime=0;
  8. std::string plist;
  9. for (base=0; base < cap; ++base)
  10. {
  11. for (test=2; test < base; ++test)
  12. {
  13. if (base % test == 0)
  14. break;
  15. else
  16. {
  17. prime=1;
  18. }
  19. }
  20.  
  21. if (prime == 1 && plist.length() < 1000)
  22. {
  23. plist += base;
  24. }
  25. }
  26. return plist;
  27. }
  28.  
  29.  
  30. std::string get_slice_of_5(const std::string concat_primes, const unsigned int n)
  31. {
  32. std::string slice;
  33. slice = concat_primes.substr (n, 5);
  34. return slice;
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40. unsigned int n;
  41.  
  42. while(std::cin >> n)
  43. {
  44. std::string concat_primes = get_concatenated_primes();
  45. std::cout << get_slice_of_5(concat_primes, n) << std::endl;
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement