这题需要判断一个数和它的反转后的数是否都为素数。
可以转成 string 后 reverse 一下。
AC CODE:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool isPrime(int x){
if(x<2) return false;
for(int i=2;i*i<=x;i++){
if(x%i==0) return false;
}
return true;
}
int main(){
int a,b;
cin>>a>>b;
for(int i=a;i<=b;i++){
int a1=i;
string res=to_string(i);
reverse(res.begin(),res.end());
int a2=stoi(res);
if(isPrime(a1)&&isPrime(a2)){
cout<<i<<endl;
}
}
return 0;
}