6845.Binomial Coefficients

Time Limit: 1s Memory Limit: 512MB

Your task is to calculate $n$ binomial coefficients modulo $10^9+7$ .

A binomial coefficient ${a \choose b}$ can be calculated using the formula $\frac{a!}{b!(a-b)!}$ . We assume that $a$ and $b$ are integers and $0 \le b \le a$ .

Input Format(From the terminal/stdin)

The first input line contains an integer $n$ : the number of calculations.

After this, there are $n$ lines, each of which contains two integers $a$ and $b$ .

  • $1 \le n \le 10^5$
  • $0 \le b \le a \le 10^6$

Output Format(To the terminal/stdout)

Print each binomial coefficient modulo $10^9+7$ .

Sample Input

Copy
3
5 3
8 1
9 5
 \n
 · \n
 · \n
 · \n

Sample Output

Copy
10
8
126
  \n
 \n
   \n
Source: CSES, Mathematics, 1079

Submit

请先 登录

© 2025 FAQs