F题 hdu 1431 素数回文

时间:2022-03-08 02:22:30

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1431

素数回文

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15041    Accepted Submission(s):
3359

Problem Description
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
 
Author
xiaoou333
 
Source
 
题目大意:找到a,b区间内及时素数又是回文的数字,并输出。看到这么大的数据量,一般都会直接选择打表的方法。
 
详见代码。
 #include <iostream>
#include <cstdio>
using namespace std;
int a[]; int sushu(int n)
{
if(n==)return ;
for(int i=; i*i<=n; i++)
if(n%i==)
return ;
return ;
}
int Find(int n)
{
int m=,t=n;
while(t)
{
m=m*+t%;
t/=;
}
if(m==n)
return ;
return ;
} int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=n;i<=m&&i<=;i++)
if (Find(i)&&sushu(i))
printf("%d\n",i);
printf("\n");
}
}