-
Notifications
You must be signed in to change notification settings - Fork 0
/
test19.cpp
46 lines (40 loc) · 918 Bytes
/
test19.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>
using namespace std;
bool isPalindromic(const vector<int>& digits) {
int left = 0, right = digits.size() - 1;
while (left < right) {
if (digits[left] != digits[right]) {
return false;
}
left++;
right--;
}
return true;
}
vector<int> convertToBase(int num, int base) {
vector<int> digits;
if (num == 0) {
digits.push_back(0);
return digits;
}
while (num > 0) {
digits.push_back(num % base);
num /= base;
}
return digits;
}
int main() {
int N, b;
cin >> N >> b;
vector<int> digits = convertToBase(N, b);
bool isPalin = isPalindromic(digits);
cout << (isPalin ? "Yes" : "No") << endl;
for (int i = digits.size() - 1; i >= 0; i--) {
cout << digits[i];
if (i != 0) {
cout << " ";
}
}
return 0;
}