88分求助!1个TLE!
查看原帖
88分求助!1个TLE!
1378709
Yue_Hao楼主2024/8/17 12:26

dalao们帮我看一下这个代码,为啥会TLE呀(最后一个样例TLE了)?感谢

#include <bits/stdc++.h>
using namespace std;
bool pd(long long n){
	for(long long i = 3; i <= ceil(sqrt(n)); i += 2) if(n % i == 0) return false;
	return true;
}
bool reint(long long n){
	long long nn = n;
	string s = "", c;
	while(nn != 0){
		c = (nn % 10 + '0');
		s.insert(0, c);
		nn /= 10;
	}
	string s1 = s;
	reverse(s1.begin(), s1.end());
	if(s1 == s){
		if( pd(n) ) return true;
		else return false;
	}else return false;
}
int main(){
	long long a, b;
	scanf("%lld %lld", &a, &b);
	if(a % 2 == 0) a += 1;
	for(long long i = a; i <= b; i += 2) if( reint(i) ) printf("%lld\n", i);
	return 0;
}
2024/8/17 12:26
加载中...