Number of Ways to Buy Pens and Pencils
You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.
Return the number of distinct ways you can buy some number of pens and pencils.
Example 1
Input
total = 20, cost1 = 10, cost2 = 5Output
9If pens cost 10 and pencils cost 5, the possible choices are 5 ways with 0 pens, 3 ways with 1 pen, and 1 way with 2 pens, for a total of 9 ways.
Example 2
Input
total = 5, cost1 = 10, cost2 = 10Output
1Both pens and pencils cost more than the total, so the only way is to buy 0 pens and 0 pencils.
Constraints
- 1 <= total, cost1, cost2 <= 10^6