AcWing 1496. 普通回文数
原题链接
简单
作者:
Value
,
2020-08-19 09:48:01
,
所有人可见
,
阅读 414
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 64;
ll a[N];
bool check(int n){
if(n == 1) return true;
for(int i = 0; i < n / 2; i ++ ){
if(a[i] != a[n - i - 1]) return false;
}
return true;
}
int main(){
ll n, b; cin >> n >> b;
int k = 0;
while(n){
a[k ++ ] = n % b;
n /= b;
}
// 特判
if(k == 0){
cout << "Yes" << endl << "0" << endl;
return 0;
}
// 检查
if(check(k)) cout << "Yes" << endl;
else cout << "No" << endl;
// 打印
for(int i = k - 1; i >= 0; i -- ){
cout << a[i];
if(i) cout << " ";
else cout << endl;
}
return 0;
}