Kevin calls a permutation perfect if the following conditions holds:
- Permutation consists of N elements.
- Permutation has K inversions.
- Number of inversions isn't bigger than number of elements in permutation (\(K \le N\)).
Kevin is interested in how many perfect permutations exist. As this number can be very big output it modulo \(1000000007 (10^9 + 7)\).
Input format:
The first line of input will contain an integer T, denoting the number of test cases.
Each of the next T lines contain two integers N and K.
Output format:
For every test case output the number of perfect permutations modulo \(10^9+7\).
Constraints:
- \(1 \le T \le 100\)
- \(K \le N\)
- (10 points): \(1 \le N \le 8, 0 \le K \le 8\)
- (10 points): \(1 \le N \le 50, 0 \le K \le 50\)
- (20 points): \(1 \le N \le 1000, 0 \le K \le 1000\)
- (20 points): \(1 \le N \le 10^9, 0 \le K \le 1000\)
- (20 points): \(1 \le N \le 10^9, 0 \le K \le 10^5, T = 1\)
- (20 points): \(1 \le N \le 10^9, 0 \le K \le 10^5\)
2 4 2 7 0
5 1
In the first case perfect permutations are (1,4,2,3) , (1,3,4,2) , (2,1,4,3) , (3,1,2,4) and (2,3,1,4).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor