document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #define UPPER_BOUND 1000000
  6.  
  7. int prime[UPPER_BOUND]= {-1,-1,0};
  8.  
  9.  
  10. int main()
  11. {
  12.     //int prime[UPPER_BOUND]= {-1,-1,0};    不能宣告在這邊。  C++陣列過大造成stack overflow http://legnaleurc.blogspot.com/2007/06/cstack-overflow.html  
  13.    
  14.     for(int i=2;i<UPPER_BOUND;i++){
  15.         if(prime[i]==0){
  16.             prime[i]=1;
  17.             for(int j=i+i;j<UPPER_BOUND;j+=i){
  18.                 prime[j]=-1;
  19.             }
  20.         }
  21.     }
  22.  
  23.     int N;
  24.     while(cin>>N){
  25.         int N_reverse=0;       
  26.         int tempN=N;
  27.         while(tempN!=0){
  28.             N_reverse *= 10;
  29.             N_reverse += tempN % 10;
  30.             tempN /= 10;
  31.         }
  32.  
  33.         if(prime[N]<0){
  34.             cout<<N<<" is not prime."<<endl;
  35.         }
  36.         else if(prime[N_reverse]>0 && N_reverse!=N){
  37.             cout<<N<<" is emirp."<<endl;
  38.         }
  39.         else{
  40.             cout<<N<<" is prime."<<endl;
  41.         }
  42.     }
  43.    
  44.     return 0;
  45. }
');