Two-Bill Purchase
Time limit0.5sMemory limit128 MB
Given a target amount D and two bill denominations P and Q, find the minimum total payment at least D achievable using nonnegative counts of each bill.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Recursion
- Solved
- No attempts yet
Problem
You can pay using only two kinds of bills: bills worth P and bills worth Q. You may use as many bills of each kind as needed.
An item costs D. To buy it, the amount paid must be at least D. Find the smallest amount that can be paid.
Input
The first line contains D, P, and Q separated by spaces. Each value is a natural number not greater than 10^9.
Output
Print the minimum amount that can be paid to buy the item.