这题应该是个红题…
题目简介
一个回文数 加二的 次方,相加可以得到 , 是题目给出的
思路
预处理出 的幂次,到 范围之内的有 个左右。
然后通过多测,每次输入一个 ,然后拿 去减预处理出的 的幂次,判断减出的数是不是回文,最多 位,可以当成 。
循环 次,也差不多是
最后,整个程序的时间复杂度为
ACcode
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
#define el '\n'
const ll N=1e2+5;
ll n;
ll a[N];
bool ishuiwen(ll x){
ll k=x;
ll y=0;
do{
y=y*10+x%10;
x/=10;
}while(x);
return (k==y);
}
void solve(){
cin>>n;
for(ll i=0;i<=log2(n)+5;i++){
if(a[i]>n) break;
if(ishuiwen(n-a[i])){
cout<<"Yes\n";
return;
}
}
cout<<"No\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("xxx.in","r",stdin);
//freopen("xxx.out","w",stdout);
a[0]=1;
for(ll i=1;i<=62;i++){
a[i]=a[i-1]*2;
}
ll T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}