Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. // ===========================
  2. // Welcome to Pocket C++
  3. // ===========================
  4. //
  5. // You can compile C++ files using F9 key (try it!).
  6. // Then you can execute the generated program pressing Ctrl+F9.
  7. //
  8. // You can use F10 to switch to the related .h header file.
  9. //
  10. // Good luck!
  11.  
  12. #include <iostream>
  13. #include <vector>
  14. #include <algorithm>
  15. #include <math.h>
  16. #include <string>
  17. #include <sstream>
  18. #include <stdint.h>
  19. #include <locale>
  20. #include <istream>
  21. #include <ios>
  22. #include <boost/lexical_cast.hpp>
  23.  
  24. using namespace std;
  25.  
  26. // Strongly-typed enums
  27. // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
  28. enum class Color : int { Red, Yellow, Blue };
  29.  
  30. string NumberToString (unsigned long number )
  31. {
  32. ostringstream ss;
  33. ss << number;
  34. return ss.str();
  35. }
  36.  
  37. bool prime(unsigned long x){
  38.  
  39. if ((fmod(x,2) == 0 and x != 2) or x == 1) return false;
  40.  
  41. for (unsigned long i = 3;i <= sqrt(x);i=i+2){
  42. if (fmod(x,i) == 0) return false;
  43. }
  44.  
  45. return true;
  46. }
  47.  
  48. bool truncate(unsigned long x){
  49.  
  50. //string str = NumberToString(x);
  51. string str = boost::lexical_cast<string>(x);
  52.  
  53. for (unsigned long i = 0; i<str.length();i++){
  54. if (not prime(boost::lexical_cast<unsigned long>(str.substr(i,str.length()-i))))
  55. return false;
  56. }
  57.  
  58. for (unsigned long i = 0; i<str.length();i++){
  59. if (not prime(boost::lexical_cast<unsigned long>(str.substr(0,str.length()-i))))
  60. return false;
  61. }
  62.  
  63. return true;
  64. }
  65.  
  66. int main(){
  67.  
  68. int i = 1;
  69. unsigned int x = 11;
  70.  
  71. while (i<=11){
  72.  
  73. if (truncate(x)){
  74. cout << x << "-" << i << "\n";
  75. i++;
  76. }
  77.  
  78. x=x+2;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement