TopCoder problem "AmountApproximation" used in SRM 274 (Division II Level Three)



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

0)
    
17
7
9
Returns: 18
18 = 7 * 0 + 9 * 2
1)
    
17
7
13
Returns: 20
20 = 7 * 1 + 13 * 1
2)
    
21
7
13
Returns: 21
21 = 7 * 3 + 13 * 0
3)
    
37
9
17
Returns: 43
43 = 9 * 1 + 17 * 2
4)
    
287341
2345
7253
Returns: 287398
287398 = 2345 * 104 + 7253 * 6

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4845

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8071&pm=4845

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Math