Problem Statement
We must pay D dollars. Unfortunately, we only have bills of two denominations: p1 dollars and p2 dollars. So, we want to overpay as little as possible.
You will be given ints D, p1 and p2. Return the minimum number of dollars greater than or equal to D that can be paid with the given bills. Assume that we have an infinite supply of both p1 and p2 dollar bills.
Definition
- Class:
- AmountApproximation
- Method:
- approximate
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int approximate(int D, int p1, int p2)
- (be sure your method is public)
Constraints
- D will be between 1 and 1000000000 (109), inclusive.
- p1 will be between 1 and 1000000000 (109), inclusive.
- p2 will be between 1 and 1000000000 (109), inclusive.
Examples
17
7
9
Returns: 18
18 = 7 * 0 + 9 * 217
7
13
Returns: 20
20 = 7 * 1 + 13 * 121
7
13
Returns: 21
21 = 7 * 3 + 13 * 037
9
17
Returns: 43
43 = 9 * 1 + 17 * 2287341
2345
7253
Returns: 287398
287398 = 2345 * 104 + 7253 * 6