~/algor $ cat problems/kombinatorika-c-n-k
Binomial coefficient queries
Medium
1000 ms
128 MB
45%
$q$ queries are given, each with integers $n$ and $k$. Find the number of ways to choose $k$ items out of $n$
$$C_{n}^{k} = \frac{n!}{k! * (n - k)!}$$
(if $k \gt n$, then $C_{n}^{k} = 0$).
Input
The first line contains a positive integer $q$. Each of the next $q$ lines contains two integers: $n$ and $k$.
Output
For each query, on a separate line, one integer — $C_{n}^{k}$ modulo $10^{9} + 7$.
Note
$1 \le q \le 10^{5}$
$0 \le n \le 10^{6}$
$0 \le k \le n + 2$
Examples
Input #1
3 5 2 10 0 4 4
Output #1
10 1 1
Input #2
2 6 3 3 5
Output #2
20 0