A high-security vault logs every completed opening with an ordinary decimal counter, but the mechanical dial mounted on the vault door itself can only display counts using a base-k numeral wheel system, one wheel per digit position. Given the counter's current decimal value and the dial's base, determine the sum of the digit values that would appear across the dial's wheels.
A single line containing two integers n and k, separated by a space — the decimal counter value and the dial's numeral base.
A single integer: the sum of the digits of n when written in base k.
Example 1
Input
34 6
Expected
9
Explanation
34 written in base 6 is "54" (5*6 + 4 = 34), so the digit sum is 5 + 4 = 9.
Example 2
Input
10 10
Expected
1
Explanation
10 written in base 10 is simply "10", so the digit sum is 1 + 0 = 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →