Banknotes for a New Game
Time limit2sMemory limit128 MB
Choose K denominations starting at 1 won where each next one is 2, 3, 4, or 5 times the previous, to minimize the number of banknotes summing to N won.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Number theory, Recursion
- Solved
- No attempts yet
Problem
A game uses banknotes as its currency. The set of banknote denominations must satisfy the following conditions.
- There are exactly K distinct denominations.
- The smallest denomination is 1 won.
- For each i, the i-th denomination is 2, 3, 4, or 5 times the (i-1)-th denomination.
A player receives N won at the start of the game. For the same amount of money, using fewer banknotes is better. You may choose any denomination set satisfying the conditions. Find the minimum number of banknotes needed to make exactly N won.
Input
The input contains two integers N and K.
Output
Print the minimum number of banknotes needed to make N won.
Constraints
- 1 ≤ N ≤ 10^18
- 1 ≤ K ≤ 100