Money Distributions
Submissions: 696   Accuracy:

10.17%

  Difficulty: Medium   Marks: 4

We want to distribute 'n' indistinguishable one Rupees coins among 'k' pupils, such that each of them receives at least one Rupees. 
We have to count the number of ways, we can distribute the amount under the given condition? Note:
Two distributions are said to be different if they have at least one pupil who got a different amount of rupees.
Since, the answer can be very large, Output it modulo 1000000007

Input:
The first line contains an Integer 't' denoting the number of test cases.
Each of the next t lines contains two Integers - n and k.

Output:
Print the total number of different such distributions Modulo 1000000007 for each test case on a new line

Constraints:
1 ≤ n,k ≤ 1000000
1 ≤ t ≤ 1000

Example:
Input:
1
7 3
Output:
15

Explanation:
We can give These amounts to its pupils.
1,1,5
1,5,1
5,1,1
2,1,4
1,2,4
1,4,2
2,4,1
4,1,2
4,2,1
3,1,3
1,3,3
3,3,1
2,2,3
2,3,2
3,2,2
so,In Total 15 ways.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Abhinav jain (iamabjain)
Author: iamabjain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.