(一个数字,将是相同的,当它被写成向前或向后被称为佩林德罗姆数字。例如,1234321 是一个回文数字。所有单位数都是回文数字。)
Output Specification:
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
将一个十进制数转换为其他进制数,判断是否为回文数字并输出转换结果
思路:写一个辗转相除取余函数来转换进制
n, b = input().split()
n, b = int(n), int(b)
def transform(num, base):
out = []
while num >= base:
out.append(num%base)
num = num//base
out.append(num)
return out
out = transform(n,b)
if out[::-1] == out:
print('Yes')
else:
print('No')
out = [str(i) for i in out[::-1]]
print(' '.join(out))