LH3223chen @ 2024-09-15 11:08:13
#include<iostream>
#include<cstring>
using namespace std;
bool zs[100000001];
void ZS(int b)
{
memset(zs, true, sizeof(zs));
{
zs[1] = false;
for (int i = 2; i * i <= b; i++)
{
if (zs[i])
{
for (int m = 2; m * i <= b; m++)
{
zs[i * m] = false;
}
}
}
}
}
bool HWS(int n)
{
int temp = n;
int m = 0;
while (temp != 0)
{
m = m * 10 + temp %10;
temp/= 10;
}
if (m == n)
return true;
else return false;
}
int main()
{
int a, b;
cin >> a >> b;
int i = a;
ZS(b);
if (i % 2 == 0)i++;
if (a > b)return 0;
if (b > 100000000)
{
b = 99999999;
}
for (i; i <= b; i++)
{
if (zs[i] && HWS(i))
{
cout << i << endl;
}
}
}
by sunhewei @ 2024-09-18 13:11:31
其实可以不用数组的 可以用循环(多层)来枚举回文数 然后判断是否是素数 这种方法是不超时的 可以试试