#include<bits/stdc++.h>
using namespace std;
const int N=10000;
int ans;
int a,b;
bool tf=true;
int f(int x)// 这个函数能生成一个数的奇数位回文数,因为奇数位的回文质数只有11,所以只需要一个函数找出所有偶数位回文数
{
ans=x;
x=x/10;
while(x!=0)
{
ans=ans*10+x%10;
x=x/10;
}
return ans;
}
int main(){
scanf("%d%d",&a,&b);
for(int x=1;x<=N;x++)
{
if(f(x)>=a&&f(x)<=b)
{
tf=true;
for(int i=2;i*i<=ans;i++)
{
if(ans%i==0)// 这里找质数
{
tf=false;
break;// 注意找到后要跳出循环
}
}
if(tf==true&&f(x)!=7) printf("%d\n",f(x));
if(tf==true&&f(x)==7) printf("%d\n%d\n",f(x),11); // 特判将11插进去,注意这两个if在循环里的位置
}
}
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交