Given two integers N and K, the task is to find the total number of ways of representing N as the sum of positive integers in the range [1, K], where each integer can be chosen multiple times.
Examples:
Input: N = 8, K = 2
Output: 5
Explanation: All possible ways of representing N as sum of positive integers less than or equal to K are:
- {1, 1, 1, 1, 1, 1, 1, 1}, the sum is 8.
- {2, 1, 1, 1, 1, 1, 1}, the sum is 8.
- {2, 2, 1, 1, 1, 1}, the sum is 8.
- 2, 2, 2, 1, 1}, the sum is 8.
- {2, 2, 2, 2}}, the sum is 8.
Therefore, the total number of ways is 5.
Input: N = 2, K = 2
Output: 2
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!