1144:素数回文

来源:互联网 发布:php去掉空格 编辑:程序博客网 时间:2024/05/21 02:51

1144:素数回文


Description

小王对既是素数又是回文的数特别感兴趣。比如说151既是素数又是个回文。现在小王想要你帮助他找出某个范围内的素数回文数,请你写个程序找出 a 跟b 之间满足条件的数。(5 <= a < b <= 100,000,000);

Input

输入a和b(5 <= a < b <= 100,000,000)

Output

按从小到大输出a,b之间所有满足条件的素数回文数

Sample Input

5 500

Sample Output

5711101131151181191313353373383


#include<iostream>using namespace std;int main(){    int a,b,i;   cin>>a>>b;    for(i=a;i<=b;i++)    {        int count=0,temp,j;       for(j=2;j<i;j++)       {        if(i%j==0)            break;       }       if(j==i)       {        temp=i;           while(temp!=0)           {               count=count*10+temp%10;               temp=temp/10;           }        }        if(count==i)            cout<<i<<endl;    }    return 0;}




原创粉丝点击