문제링크 : https://www.acmicpc.net/problem/11576
import sys
read = lambda : sys.stdin.readline().strip()
a, b = map(int, read().split())
num = int(read())
a_ver_num = list(map(int, read().split()))
a_ver_num.reverse()
sum = 0
for i in range(num):
sum += (a_ver_num[i]* (a**i))
b_ver_num = []
while sum > 0:
b_ver_num.append(str(sum % b))
sum //= b
b_ver_num.reverse()
print(" ".join(b_ver_num))