素数回文
来源:互联网 发布:淘宝曝光量是什么意思 编辑:程序博客网 时间:2024/05/02 00:57
#include <iostream>
#include <cstring>
using namespace std;
const int Max = 10000000;
int prime[1000000];
int ans[10000];
bool is_prime[Max];
int p = 0;
void getPrime() //找出素数放在数组prime中
{
int i, j;
memset(is_prime, true, sizeof(is_prime)); //筛选法求素数
is_prime[0] = is_prime[1] = false;
for(i = 2; i < Max; i++)
{
if(is_prime[i])
{
prime[p++] = i;
for(j = 2 * i; j < Max; j += i)
is_prime[j] = false;
}
}
}
int isIt(int a) //判断回文
{
int x = a;
int y = 0;
while(x > 0)
{
y = y * 10 + x % 10; //判断回文数
x /= 10;
}
if(y == a)
return 1;
else
return 0;
}
int main()
{
int a, b, i, j = 0;
getPrime();
for(i = 0; i < p; i++) //找出回文素数,放在ans数组中
if(isIt(prime[i]))
ans[j++] = prime[i];
while(cin >> a >> b)
{
for(i = 0; i < j; i++)
{
if(a > ans[i])
continue;
else if(ans[i] <= b)
printf("%d\n", ans[i]);
else
break;
}
printf("\n");
}
return 0;
}
- 素数回文
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 【素数回文】
- 回文素数
- 素数回文
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 回文素数
- 素数回文
- 菜狗的C++ primer读书笔记:第一章 开始
- 简单的冒泡排序06
- uri个url的区别
- 长链剖分随想
- 了解UART串口驱动
- 素数回文
- 10分钟精通SharePoint - SharePoint升级
- 递归--九度1458.汉诺塔3
- 第28天(就业班) 自定义mvc框架、Struts入门及执行流程、环境搭建
- LCD显示时钟
- Deep Learning(深度学习)学习笔记整理系列之LeNet-5卷积参数个人理解
- 寒假作业
- MMAP使用
- 每日更新【Python】常用方法