回文质数
来源:互联网 发布:apache本地服务器搭建 编辑:程序博客网 时间:2024/06/08 15:41
描述
因为151既是一个质数又是一个回文数(从左到右和从右到左看是一样的),所以151是回文质数.
写一个程序来找出范围[a,b](5<=a<b<=100,000,000)间的所有回文质数.
写一个程序来找出范围[a,b](5<=a<b<=100,000,000)间的所有回文质数.
输入
第一行 两个整数:a和b.
输出
输出一个回文质数的列表,一行一个.
输入样例
5 500
输出样例
5
7
11
101
131
151
181
191
313
353
373
383
7
11
101
131
151
181
191
313
353
373
383
#include<iostream>
#include<cmath>using namespace std;
int prime(int m)
{
int i;
if(m==1)
{
return 0;
}
for(i=2;i<=sqrt(m);i++)
{
if(m%i==0)
{
return 0;
}
}
return 1;
}
int hws(int a)
{
int sum,a1;
a1=a;
sum=0;
while(a!=0)
{
sum=10*sum+a%10;
a=a/10;
}
if(sum==a1)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int a,b,i;
cin>>a>>b;
if(b>10000000)
{
b=9989899;
}
else
{
b=b;
}
for(i=a;i<=b;i++)
{
if(hws(i)==1)
{
if(prime(i)==1)
{
cout<<i<<endl;
}
}
}
return 0;
}
阅读全文
0 0
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数 构造回文数
- 1.5 回文质数
- 【回文质数】搜索
- 查找回文质数
- idea cannot find declaration to go to
- WebPack使用流程小记
- 数据分析的统计学基础--相关及回归分析
- mysql alter
- 这么简单的道理,猩猩都懂,我们却忘了
- 回文质数
- PAT甲级 1051. Pop Sequence (25)
- Daily summary
- JSP中的button按钮杂说
- Android中Fragment的Hide和Show
- A child container failed during start java.lang.ClassCastException: org.springframework.web.SpringSe
- Android | MVC设计模式
- 在Centos 7 下redis的安装
- 利用jTessBoxEditor工具进行Tesseract3.02.02样本训练,提高验证码识别率