66分-最后三项TLE,求解
查看原帖
66分-最后三项TLE,求解
992634
yingshihao楼主2023/10/25 22:02

大家猜得没错的话最后三项TLE


最后三个TLE 去缓冲区了,但十几万时就一秒了 题解全是打表的不想打表求解

程序如下

#include <iostream>
#include <cmath>
#define int long long
using namespace std;
bool ss(int a){
	if(a<2) return false;
	if(a==2) return true; 
	for(int i=2;i<=sqrt(a);i++){
		if(a%i==0) return false;
	}
	return true;
}
bool hws(int x){
	int s=0,p;
	p=x;
	while(p!=0){
		s=s*10+p%10;
		p=p/10;
	}
	if(x==s){
		return true;
	}else{
		return false;
	}
}
signed main(){
	int a,b;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	switch(a%2){
		case 0:
			for(int i=a+1;i<=b;i+=2){
				if(ss(i)&&hws(i)){
					cout<<i<<endl;
				}
			}
			return 0;
		case 1:
			for(int i=a;i<=b;i+=2){
				if(ss(i)&&hws(i)){
					cout<<i<<endl;
				}
			}
			return 0;
	}
	return 0;
}
2023/10/25 22:02
加载中...