Exponential Arithmetic
You are given a starting number and an exponentiation base
.
Your goal is to reduce to exactly
using as few operations as possible.
In a single operation, you may subtract any integer power of with a non-negative exponent. In other words, you may choose any integer
and perform:
You may only perform an operation if the resulting value of is non-negative.
Determine the minimum number of operations required to reduce to
.
Input
The input consists of a single line containing two integers (
) and
(
).
represents the starting number, and
represents the base used for exponentiation.
Output
Output a single integer representing the minimum number of operations required to reduce to
.
Examples
Input 1
10 2
Output 1
2
We can reduce to
in two operations:
There is no shorter sequence of operations.
Input 2
7 2
Output 2
3
We can reduce to
in three operations:
There is no shorter sequence of operations.
Comments