문제 확인하기
2. 정답 코드 (python3, memory: 33240KB, time: 72ms)
import math
input_base, output_base = map(int, input().split())
num_digits = int(input())
digits_list = list(map(int, input().split()))
decimal_num = 0
output_result = []
output_str = ''
for i in range(num_digits):
decimal_num += int(digits_list[i] * math.pow(input_base, num_digits - i - 1))
while decimal_num:
remainder = decimal_num % output_base
output_result.append(str(remainder))
decimal_num = decimal_num // output_base
output_result = output_result[::-1]
output_str = ' '.join(output_result)
print(output_str)