Problem E: 回文素数
Description
定义一个类SpecialPrime,只有一个静态成员函数
bool judge(int value)
用于判断value是否是一个回文素数。所谓回文素数是指一个数既是回文数又是素数。
Input
输入两个数m和n,0<m<n。
Output
区间[m,n]内的所有回文素数。
Sample Input
2 1000
Sample Output
2
3
5
7
11
101
131
151
181
191
313
353
373
383
727
757
787
797
919
929
算法一
#include<bits/stdc++.h>
using namespace std;
int prime[1000010];
class SpecialPrime
{
private:
public:
static int flag;
static bool judge(int value)
{
int s[1000];
int cnt = 0;
if(flag==0)
{
make_prime();
flag = 1;
}
if(prime[value]==1)
{
return false;
}
while(value!=0)
{
s[cnt] = value%10;
value = value/10;
cnt++;
}
for(int i = 0; i<cnt; i++)
{
if(s[i]!= s[cnt-1-i])
{
return false;
}
}
return true;
}
static void make_prime()
{
memset(prime,0,sizeof(prime));
for(int i =2; i<sqrt(1000000); i++)
{
if(prime[i] == 0)
{
for(int j = i*i