python算法题--简单-- K 进制表示下的各位数字总和
class Solution:
def sumBase(self, n: int, k: int) -> int:
tag = True
quotient = n//k #商
remainder = n%k #余数
while tag:
if quotient >= k:
remainder+=quotient%k #若商比k大,则可以继续除下去,将余数加至remainder
quotient//=k
else:
remainder+=quotient #若商小于k,则剩余的商即为余数,加至remainder
tag=False
return remainder