Liboy53_I_HATE_MATH @ 2024-02-12 09:12:47
#include<bits/stdc++.h>
using namespace std;
bool prime(int a)
{
bool flag=true;
if(a==1) return false;
else
{
for(int j=2;j<=sqrt(a);j++)
{
if(a%j==0)
{
flag=false;
break;
}
else continue;
}
if (flag||a==2||a==3) return true;
else return false;
}
}
bool back_num(int a){
int b=a;
int c=0;
while(b>0)
{
c=c*10+b%10;
b/=10;
}
return c==a;
}
int main(){
int a,b,c;
scanf("%d%d",&b,&c);
for(a=b;a<=c;a++)
{
if(a>9989899) break;
if((a>7996997&&a<9002009)|(a<7014107&&a>3998993)||(a<3001003&&a>1998991)||(a<1003001&&a>98689)) continue;
if(prime(a)&&back_num(a)) printf("%d\n",a);
}
return 0;
}
最后三测试点TLE了,本蒟蒻无能为力
by loser_wanghan @ 2024-02-12 09:54:59
重写代码吧,5≤a<b≤100,000,000 肯定 TLE
by Liboy53_I_HATE_MATH @ 2024-02-12 18:14:28
@loser_wanghan 那枚举回文数再判断素数可以吗
by loser_wanghan @ 2024-02-12 23:21:59
@Liboy53_I_HATE_MATH 好像可以,你试试