同标题,代码如下
#include<iostream>
#include<cmath>
using namespace std;
bool num(int x);
bool num(int x)
{
int j=2;
if(x<2)
{
return false;
}
else
{
while(j<=sqrt(x)&&x%j!=0)
{
j++;
}
if(j>sqrt(x)) return true;
else return false;
}
}
int abba(int x);
int abba(int x)
{
int a=0;
while(x>0)
{
a=a*10+x%10;
x/=10;
}
return a;
}
int main()
{
int x,y,z=0,st=1;
cin>>x>>y;
for(int i=x;i<=y;i++)
{
if(num(i)&&abba(i)==i)
{
if(st==1)
{
st=0;
}
else
{
cout<<endl;
}
cout<<i;
}
}
return 0;
}