Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ===========================
- // Welcome to Pocket C++
- // ===========================
- //
- // You can compile C++ files using F9 key (try it!).
- // Then you can execute the generated program pressing Ctrl+F9.
- //
- // You can use F10 to switch to the related .h header file.
- //
- // Good luck!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <string>
- #include <sstream>
- #include <stdint.h>
- #include <locale>
- #include <istream>
- #include <ios>
- #include <boost/lexical_cast.hpp>
- using namespace std;
- // Strongly-typed enums
- // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
- enum class Color : int { Red, Yellow, Blue };
- string NumberToString (unsigned long number )
- {
- ostringstream ss;
- ss << number;
- return ss.str();
- }
- bool prime(unsigned long x){
- if ((fmod(x,2) == 0 and x != 2) or x == 1) return false;
- for (unsigned long i = 3;i <= sqrt(x);i=i+2){
- if (fmod(x,i) == 0) return false;
- }
- return true;
- }
- bool truncate(unsigned long x){
- //string str = NumberToString(x);
- string str = boost::lexical_cast<string>(x);
- for (unsigned long i = 0; i<str.length();i++){
- if (not prime(boost::lexical_cast<unsigned long>(str.substr(i,str.length()-i))))
- return false;
- }
- for (unsigned long i = 0; i<str.length();i++){
- if (not prime(boost::lexical_cast<unsigned long>(str.substr(0,str.length()-i))))
- return false;
- }
- return true;
- }
- int main(){
- int i = 1;
- unsigned int x = 11;
- while (i<=11){
- if (truncate(x)){
- cout << x << "-" << i << "\n";
- i++;
- }
- x=x+2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement