擅长:python、mysql、java
<pre><code>num = 45
base = 3
num_base = []
remainder = num
# the remainders of the integer divisions of the number by the base are the digits of the number in the new base
# see also here: https://math.stackexchange.com/questions/111150/changing-a-number-between-arbitrary-bases
while remainder:
num_base.append(remainder % base)
remainder //= base
# join the list in reverse while changing type of digits to characters
print("".join(str(x) for x in num_base[::-1]))
</code></pre>