Environment: Python 3.8
Key technique: //, %
Given an integer
n (in base
10) and a base
k, return the sum of the digits of
n after converting
n from base
10 to base
After converting, each digit should be interpreted as a base
10 number, and the sum should be returned in base
Input: n = 34, k = 6
Explanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
- Calculate quotient and remainder between n and k.
- If update n > k, continue step1.
- If update n≤k, stop calculate.
- Summarize the current quotient and remainder.
def sumBase(self, n: int, k: int) -> int:
return ans +n