回文素数
来源:互联网 发布:五大流氓国笑话知乎 编辑:程序博客网 时间:2024/04/28 15:12
#include <iostream>#include <cmath> using namespace std;int Prime(long int w) { int a, b,c; a = w%2; b=3; c=(int)sqrt((double)w); while (a&&b<=c) { a=w%b; b+=2; } return a; } int main() { int a,b,c,d,e; int m,n; long int w; while(cin >> m >> n) { a=0; b=0; c=0; d=0; e=4; while (a<=9) { e++; if (e==10) { e=0; d++; } if (d==10) { d=0; c++; } if (c==10) { c=0; b++; } if (b==10) { b=0; a++; } w=a*100000000+b*10000000+c*1000000+d*100000+e*10000+d*1000+c*100+b*10+a; while (w%10==0) { w=w/10; } if( w >= m && w < n ) { if (Prime(w)) { cout << w << endl; if (w>5&&w<100) { cout << 11 <<endl; } } } } cout << endl; } return 0; }
第二代码,西西里上的题,输入0 0时结束程序
#include<iostream>#include<cstdio>#include<cmath>using namespace std;const int maxn=10000;int a,b;int ans[maxn];bool ask(int x){ for (int i=2; i<=sqrt(x); i++) if (x%i==0) return false; return true;}void prepare(){ for (int i=1; i<=maxn; i++){ int state=i,tmp=i/10; while (tmp!=0){ state=state*10+tmp%10; tmp/=10; } if (ask(state)) ans[++ans[0]]=state; if (state==7) ans[++ans[0]]=11; }}inline int init(){ while (scanf("%d%d",&a,&b)!=EOF){ if(a==0&&b==0) return 0; for (int i=1; i<=ans[0]; i++) if ((ans[i]>=a) && (ans[i]<=b)) printf("%d\n",ans[i]); } return 0;}int main(){ prepare(); init(); return 0;}
法3:
bool checkPri(int n){bool b=true;for(int i=2;i<=n/2;i++){if(n%i==0){b=false;break;}}return b;}
- 素数回文
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 【素数回文】
- 回文素数
- 素数回文
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 素数回文
- Failed to create the Java Virtual Machine 解决方法
- YiiFrameworkBlog开发向导:添加和更新文章
- 插值查找算法
- umount目前device busy的文件系统
- 使用PeopleCode手动更新Grid里面的数据?
- 回文素数
- StageFright框架流程解读 .
- checkbox 全选、取消全选等并且获取checkbox的值
- Android应用自动更新功能的实现!!!
- 在App Engine 中实现动态调用Section
- 解决异常All Processing Suspended: Restart OPRID=%1 RUNID=%2, PI=%3
- jprofiler 远程监控aix的jvm
- 各大城市人口排名
- Windows Runtime (RT)