NOJ1128 回文质数
来源:互联网 发布:国家网络风险评估标准 编辑:程序博客网 时间:2024/06/14 09:50
描述
因为151既是一个质数又是一个回文数(从左到右和从右到左看是一样的),所以151是回文质数.
写一个程序来找出范围a,b间的所有回文质数.
输入
第一行 两个整数:a和b.
输出
输出一个回文质数的列表,一行一个.
输入样例
5 500
输出样例
5
7
11
101
131
151
181
191
313
353
373
383
#include <iostream>#include <cstring>#include <sstream>#include <cmath>using namespace std;const int maxn = 1e8;bool vis[maxn];void Eratos(int a, int b) { //Eratosthenes筛法 memset(vis, 0, sizeof(vis)); int m = sqrt(b+0.5); for(int i = 2; i <= m; i++) if(!vis[i]) for(int j = i*i; j <= b; j+=i) vis[j] = 1;}string num2str(int n) { stringstream sstream; string s; sstream << n; sstream >> s; return s;}bool isPalin(int n) { //Palindrome string s = num2str(n); for(int i = 0, j = s.length()-1; i <= j; i++, j--) if(s[i] != s[j]) return false; return true;}int main() { int a, b; while(cin >> a >> b) { Eratos(a, b); for(int i = a; i <= b; i++) if(!vis[i] && isPalin(i)) cout << i << endl; } return 0;}
1 0
- NOJ1128 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数
- 回文质数 构造回文数
- 1.5 回文质数
- 【回文质数】搜索
- 基础练习 01字串
- TIMUS-1748. The Most Complex Number-求反素数(数学+搜索)
- Android基于监听的事件处理机制
- 使用多线程去复制一个文件,我们可以指定文件名和线程数
- https://localhost:1158/em 页面无法打开的问题
- NOJ1128 回文质数
- iOS陆先森开发随笔(三)iOS调试技巧(debug)
- HDU 1016(Java) 好大一个坑!!!
- 83. Remove Duplicates from Sorted List
- Oracle RAC CRS-0184 --Cannot communicate with the CRS daemon
- 机器学习推荐资源
- Apriori算法
- 11g RAC不能启动ohasd进程
- Java虚拟机类加载过程