#K44422. Binomial Coefficient Computation
Binomial Coefficient Computation
Binomial Coefficient Computation
You are given two integers (n) and (k). Your task is to compute the binomial coefficient (C(n, k)) modulo (10^9+7). The binomial coefficient is defined as (C(n, k)=\frac{n!}{k!(n-k)!}) and is read as "n choose k". Note that if (k < 0) or (k > n), the result is defined to be 0.
The problem requires you to use modular arithmetic and Fermat's Little Theorem to compute the modular inverse when necessary. Make sure that your solution reads input from standard input (stdin) and writes the output to standard output (stdout).
inputFormat
The input consists of a single line containing two space-separated integers (n) and (k).
outputFormat
Output a single integer representing (C(n, k)) modulo (10^9+7).## sample
10 2
45