lanmengfei @ 2023-04-02 09:24:35
贴代码:
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int n){
for (int i=2;i*i<=n;i++){
if (n%i==0)return 0;
}
return 1;
}
bool is_hws(int n){
int x=0,y=n;
while (n!=0){
x=x*10+n%10;
n/=10;
}
return (x==y);
}
int main(){
int n,m;
cin>>n>>m;
for (int i=n;i<=m;i++){
//cout<<is_prime(i)<<" "<<is_hws(i)<<endl;
if (is_prime(i) and is_hws(i)){
cout<<i<<endl;
}
}
return 0;
}
样例都是通过的,只有29行,为什么会TLE?求大佬帮一下
by I_am_kunzi @ 2023-04-02 09:26:25
其实吧,所有的回文质数都小于一百万...
by wang1h @ 2023-04-02 09:37:45
注意范围
by wang1h @ 2023-04-02 09:39:52
@lanmengfei
另,题目范围内最大回文质数为
by lanmengfei @ 2023-04-02 15:55:34
@wang1h 谢谢