FunctionRacerProblemsRace

Digit Sum in Base K

BeginnerMathPython, JavaScript, TypeScript, Java, C++

Write n in base k, then add up its digits, treating each digit as an ordinary base 10 number. Return that sum as a base 10 integer.

Example 1

n 34
k 6
returns 9

34 is 54 in base 6, and 5 + 4 = 9.

Example 2

n 10
k 10
returns 1

1 + 0 = 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems