#C5556. Coin Toss Combinations

    ID: 49218 Type: Default 1000ms 256MiB

Coin Toss Combinations

Coin Toss Combinations

Given a set of N coins, your task is to determine the number of ways to have exactly K coins show heads. This is mathematically equivalent to computing the binomial coefficient:

$$ C(n, k) = \frac{n!}{k!(n-k)!} $$

If K exceeds N, then it is impossible to have exactly K heads and the answer should be 0.

inputFormat

The input starts with a single integer T on the first line, representing the number of test cases. Each of the following T lines contains two space-separated integers N and K, where N is the total number of coins and K is the desired number of heads.

outputFormat

For each test case, output a single line containing the number of ways to obtain exactly K heads from N coins. If it is not possible, output 0.## sample

3
5 3
4 2
6 0
10

6 1

</p>