NewMoneySystem
SRM 325 · 2006-11-02 · by Andrew_Lazarev
Problem Statement
You are creating the money system for a new game. The requirements are as follows:
- There will be exactly K different banknote values.
- The value of the smallest banknote will be equal to one dollar.
- The value of the i-th banknote will be equal to the value of the (i-1)-th banknote multiplied by 2, 3, 4 or 5.
The initial capital of a player will be N dollars, so you want to choose banknote values in such a way that minimizes the number of banknotes required to make N dollars. Assume that you have an infinite supply of banknotes for each value.
You will be given two integers N and K. Due to technical reasons, N will be given as a
Constraints
- N will be an integer between 1 and 1018, inclusive, with no leading zeros.
- K will be between 1 and 100, inclusive.
"1025" 6 Returns: 2
The best set of banknote values is {1, 4, 16, 64, 256, 1024}. 1025 = 1024 + 1.
"1005" 5 Returns: 3
The best set of banknote values is {1, 5, 25, 100, 500}. 1005 = 2 * 500 + 5.
"12000" 14 Returns: 1
"924323565426323626" 1 Returns: 924323565426323626
The answer can be rather big.
"924323565426323626" 50 Returns: 10
Submissions are judged against all 88 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class NewMoneySystem with a public method long long chooseBanknotes(string N, int K) · 88 test cases · 2 s / 256 MB per case