【HDU 1431】素数回文
来源:互联网 发布:机构投资者持股数据 编辑:程序博客网 时间:2024/05/01 08:01
素数回文
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18606 Accepted Submission(s): 4332
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
5711101131151181191313353373383思路:打表#include<bits/stdc++.h>#define manx 9989899+1 //最大的回文素数using namespace std;bool s[manx];int p[manx];void prime(){ memset(s,true,sizeof(s)); for (int i=2; i<=manx; i++){ if(s[i]){ for (int j=i+i; j<=manx; j+=i) s[j]=false; } }}bool hui(int n){ int x=0,t=n; while(t){ x=x*10+t%10; t/=10; } if(x==n) return true; return false;}int cot;void fun(){ for (int i=5; i<=manx; i++){ if(s[i] && hui(i)) p[cot++]=i; }}void solve(){ int a,b; while(~scanf("%d%d",&a,&b)){ for (int i=0; i<cot; i++){ if(p[i] > b) break; if(p[i] >= a) printf("%d\n",p[i]); } printf("\n"); }}int main(){ prime(); fun(); solve(); return 0;}
0 0
- hdu 1431 素数回文
- hdu 1431 素数回文
- HDU-1431-素数回文
- hdu 1431 素数回文
- HDU 1431 素数回文
- Hdu 1431 - 素数回文
- hdu 1431 素数回文
- hdu 1431(素数回文)
- HDU-1431素数回文
- hdu 1431 素数回文
- hdu 1431 素数回文
- hdu 1431 素数回文
- hdu 1431 素数回文
- hdu 1431 素数回文
- hdu 1431 素数回文
- HDU 1431 素数回文
- HDU 1431 素数回文
- 素数回文 HDU 1431
- RealFlow在线教程翻译(11)——SPH
- c++第二次作业-3定期存款利息计算器
- NHibernate+FluentNHibernate+MySql 运行报错问题
- c++第二次实验:输出完数
- Spring AOP 实现原理
- 【HDU 1431】素数回文
- python,Cocos2d-x,关于配置python后出现的问题,导致命令行失效,
- LAMP服务器优化---Nginx
- GYM 100247 A. The Power of the Dark Side(水~)
- Spring AOP
- [IOS APP]曾仕强演说精选-有声系列
- HDU 3652 B-number
- 数据库事务四种隔离级别
- spring 的platformTrasactionoManager API讲解(翻译)