66分求助
查看原帖
66分求助
945549
jwsdy楼主2023/9/15 17:12

7,8,9点超时

#include<bits/stdc++.h>
using namespace std;
int a,b;
bool ss(int s){
	if(s<=1)
	return false;
	for(int i=2;i<=sqrt(s);i++){
		if(s%i==0)
		return false;
	}
	return true;
}
bool huiwen(int s){
	int x[20];
	memset(x,0,sizeof(x));
	int n=0;
	while(s!=0){
		x[++n]=s%10;
		s/=10;
	}
	for(int i=1;i<=n;i++)
	if(x[i]!=x[n-i+1]) return false;
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>a>>b;
	if(a%2==0) a++;
	for(int i=a;i<=b;i+=2){
		if(ss(i)&&huiwen(i))
		cout<<i<<endl;
	}
	return 0;
}

求大佬可以解决蒟蒻的问题
顺便告诉蒟蒻为什么这位谷友的代码不会超时,而我的却会
万分感谢

2023/9/15 17:12
加载中...