F题 hdu 1431 素数回文

题目链接: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区间内及时素数又是回文的数字,并输出。看到这么大的数据量,一般都会直接选择打表的方法。
 
详见代码。
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int a[10000001];
 5 
 6 int sushu(int n)
 7 {
 8     if(n==2)return 1;
 9     for(int i=2; i*i<=n; i++)
10         if(n%i==0)
11             return 0;
12     return 1;
13 }
14 int Find(int n)
15 {
16     int m=0,t=n;
17     while(t)
18     {
19         m=m*10+t%10;
20         t/=10;
21     }
22     if(m==n)
23         return 1;
24     return 0;
25 }
26 
27 int main()
28 {
29     int n,m;
30     while(cin>>n>>m)
31     {
32         for(int i=n;i<=m&&i<=9989899;i++)
33             if (Find(i)&&sushu(i))
34                 printf("%d
",i);
35         printf("
");
36     }
37 }
 
原文地址:https://www.cnblogs.com/qq-star/p/4622962.html