1217 66分-最后三项TLE--求解
  • 板块灌水区
  • 楼主yingshihao
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/29 09:21
  • 上次更新2023/11/2 10:58:16
查看原帖
1217 66分-最后三项TLE--求解
992634
yingshihao楼主2023/10/29 09:21

最后三项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/29 09:21
加载中...