stksgg @ 2023-01-07 22:17:22
#include<iostream>
using namespace std;
#include<stdio.h>
#include<cmath>
#include<cstring>
bool su(int x)
{
if (x == 2 || x == 3)
{
return true;
}
for (int i = 2; i <= (int)sqrt(x); i += 2)
{
if (x % i == 0)
{
return false;
}
i--;
}
return true;
}
bool hui(char s[])
{
for (int i = 0; i <=(int)strlen(s)/2; i++)
{
if (s[i] == s[strlen(s) - i - 1])
{
}
else
{
return false;
}
}
return true;
}
int main()
{
char x[13];
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++)
{
sprintf(x, "%d", i);
//s = x;
if (hui(x))
{
if (su(i))
{
printf("%d\n",i);
}
}
else
{
}
}
}
by cy_AK_CSP_ing @ 2023-02-23 12:15:24
四位数,六位数,八位数都不可能是回文质数因为四位回文数假设是xyyx,那么它的值是1000x+100y+10y+x=1001x+110y,1001和110都可以被11整除。六位回文数假设是abccba它的值是100000a+10000b+1000c+100c+10b+a=100001a+10010b+1100c100001,10010,1100都可以被11整除,以此类推,8位数也是一样,你可以用这个方法优化。