55分,tle
查看原帖
55分,tle
258364
Ga_Ming楼主2021/7/25 16:10
#include<bits/stdc++.h>
#define ll long long
using namespace std;

bool isp(ll n){
	if(n==2) return true;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0) return false;
	}
	return true;
}

bool pld(ll n){
	stack<int>st1;
	stack<int>st2;
	ll mry=n;
	while(mry>0){
		st1.push(mry%10);
		st2.push(mry%10);
		mry/=10;
	}
	int sz=st1.size();
	int pos[15],neg[15];
	for(int i=sz-1;i>=0;i--){
		pos[i]=st1.top();
		st1.pop();
	}
	for(int i=0;i<sz;i++){
		neg[i]=st2.top();
		st2.pop();
	}
	for(int i=0;i<sz;i++){
		if(pos[i]!=neg[i]) return false;
	}
	return true;
	
}

ll a,b;

int main(){
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(isp(i)&&pld(i)) cout<<i<<endl;
	}
	return 0;
}
2021/7/25 16:10
加载中...