xiaoou33对既是素数又是回文的数特别感兴趣。比如说151既是素数又是个回文。现在xiaoou333想要你帮助他找出某个范围内的素数回文数,请你写个程序找出 a 跟b 之间满足条件的数。(5 <= a < b <= 100,000,000);
Input
这里有许多组数据,每组包括两组数据a跟b。
Output
对每一组数据,按从小到大输出a,b之间所有满足条件的素数回文数(包括a跟b)每组数据之后空一行。
Sample Input
5 500
Sample Output
5
7
11
101
131
151
181
191
313
353
373
383
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;
int a[10000001];
int sushu(int n)
{
if(n==2)
{
return 1;
}
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
int find(int n)
{
int m=0,t=n;
while(t)
{
m=m*10+t%10;
t/=10;
}
if(m==n)
{
return 1;
}
return 0;
}
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=n; i<=m&&i<=9989899; i++)
{
if (find(i)&&sushu(i))
{
printf("%d\n",i);
}
}
printf("\n");
}
}
#include <iostream>
#include <cstdio>
using namespace std;
int a[10000001];
int sushu(int n)
{
if(n==2)
{
return 1;
}
for(int i=2; i*i<=n; i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
int find(int n)
{
int m=0,t=n;
while(t)
{
m=m*10+t%10;
t/=10;
}
if(m==n)
{
return 1;
}
return 0;
}
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=n; i<=m&&i<=9989899; i++)
{
if (find(i)&&sushu(i))
{
printf("%d\n",i);
}
}
printf("\n");
}
}