Skip to content

Practice Number of Ways to Buy Pens and Pencils

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2240
LeetCode Problem

Number of Ways to Buy Pens and Pencils

Problem Statement

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.

Source: Number of Ways to Buy Pens and Pencils on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
total = 20, cost1 = 10, cost2 = 5
Output
9

# Example 2

Input
total = 5, cost1 = 10, cost2 = 10
Output
1

Constraints

1 <= total, cost1, cost2 <= 10^6

Related LeetCode Problems

Practice more problems similar to Number of Ways to Buy Pens and Pencils.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.