codeprocessing @ 2023-10-04 09:17:05
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int a,b,d;
char c[10];
bool Fun_SS(int h){
for(int i=2;i*i<=h;++i){
if(h%i==0)
return 0;
}
return 1;
}
bool Fun_HW(int e,string n){
if(n.size()==1){
if(Fun_SS(e)) return 1;
else return 0;
}
string s;
s=n;
int u=s.size();
reverse(s.begin(),s.end());
if(s==n){
if(Fun_SS(e)==1) return 1;
else return 0;
}
else return 0;
}
int main(){
cin>>a>>b;
if(a%2==0)
a++;
for(int i=a;i<=b;i=i+2){
sprintf(c,"%d",i);
string l=c;
if(Fun_HW(i,l))cout<<i<<endl;
}
return 0;
}
by __D_A_T__ @ 2023-10-04 09:19:28
关闭同步流再试试
by DANNNqwq @ 2023-10-04 09:28:57
观察一下a=1,b=100000000
时可以发现在1e7~1e8这个区间内没有回文素数,就可以特判一下if(b>1e7) b=1e7;
by codeprocessing @ 2023-10-04 10:44:25
@DANNNsth 感谢