MYQ5 - The Nerd Factor

no tags 

Prof.Venky handles Advanced Topics in Algorithms course for a class of 'n' students. He is always known for his unsolvable question papers. Knowing that it is impossible to pass his subject in a fair manner, one of the students of his class, Vishy, finds out from his seniors that Prof.Venky won't be able to find out if at least 'k' students together discuss and write the answers and thereby all of them can pass. Hence they decide to divide the whole class into a number of groups so that everyone passes. But all the students are fighting over forming the groups. So Puppala, one of the nerdy students in the class, decides  that he will compute all possible ways that they can form the groups and number them, and finally choose one of those numbers at random and go ahead with that way. Now it is your duty to help Puppala find the number of  ways that they can form such groups. 

Pupalla is incapable of reading big numbers, so please tell him the answer modulo 10^9+7.

Input

The first line contains the number of test case t(1<=t<=10^6).
Followed by t lines for each case.
Each test case contains two integers 'n' and 'k' separated by a space(1<=k,n<=1000)

Output

For each test case, print a single line containing one positive integer representing the number of ways modulo 10^9+7 .

Example

Input:
3 
2 1
4 2
6 2 Output: 2
2
4

hide comments
Gurpreet Singh: 2012-12-18 17:19:00

Edit : AC'ed :-)

Last edit: 2012-06-30 20:41:53
sandeep pandey: 2012-05-01 04:47:44

Nice One..:)

Mitch Schwartz: 2012-02-29 08:23:24

The text is not clear about what we are supposed to be counting. From my interpretation, we are supposed to count the number of ways to divide n people into 1 or more unlabelled groups such that each group has at least k members. But then for (4,2) the answer should be 4:

{{1,2},{3,4}}
{{1,3},{2,4}}
{{1,4},{2,3}}
{{1,2,3,4}}

Please clarify.

Edit: Ok, after looking at the expected output some more, it seems we are supposed to treat the people as identical to each other, which is very non-standard for combinatorics problems. In this case normally we talk about dividing balls into groups, or some such. So we only care about the size of each group. For (4,2) we count

{2,2}
{4}

to get the answer 2.

(From AC, I can confirm this is the correct interpretation.)

Last edit: 2012-03-06 09:11:56

Added by:jack(chakradarraju)
Date:2012-02-14
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Bytecode 2012