官方题解。
容易发现,当 时,。故枚举 ,判断 是否是回文数即可。复杂度 。
实现
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
bool check(ll x){
ll rev = 0, t = x;
while (x){
rev = rev * 10 + x % 10;
x /= 10;
}
return rev == t;
}
void solve(){
cin >> n;
for (int i = 0; ; i++){
if (n - (1ll << i) < 0){
cout << "No" << "\n";
break;
}
if (check(n - (1ll << i))){
cout << "Yes" << "\n";
break;
}
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--){
solve();
}
return 0;
}