最后一个样例超时怎么办,萌新求教。
查看原帖
最后一个样例超时怎么办,萌新求教。
605248
tctd613楼主2022/1/24 13:55
#include<bits/stdc++.h>
using namespace std;
int a[20];
bool s(int x){
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return false;
	}
	return true;
}
bool h(int x){
	int i=x,s=0;
	while(i!=0){
		s=s*10+i%10;
		i/=10;
	}
	if(s==x) return true;
	else return false;
}
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(h(i)&&s(i)) cout<<i<<endl;
	}
	return 0;
}
2022/1/24 13:55
加载中...