Skip to content

2240. Number of Ways to Buy Pens and Pencils

Leetcode - 2240. Number of Ways to Buy Pens and Pencils

Submission

class Solution {
    public long waysToBuyPensPencils(int total, int cost1, int cost2) {
        long ans = 0;
        long penOptions = total / cost1;
        for (int i = 0; i <= penOptions ; i++) {
            ans += (total - cost1 * i) / cost2 + 1;
        }

        return ans;
    }
}