#K75877. Candy Distribution

    ID: 34517 Type: Default 1000ms 256MiB

Candy Distribution

Candy Distribution

You are given \(N\) candies and \(K\) children. Your task is to determine the number of ways to distribute all the candies such that each child receives at least one candy. This is equivalent to finding the number of positive integer solutions to the equation: \(x_1 + x_2 + \cdots + x_K = N\), where \(x_i \ge 1\) for all \(i\). By using the stars and bars theorem, the answer can be computed as \(\binom{N-1}{K-1}\) if \(K \le N\), otherwise the answer is 0.

inputFormat

The first line contains an integer \(T\), 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 candies and \(K\) is the number of children.

outputFormat

For each test case, output a single line containing the number of ways to distribute the candies according to the given condition.

## sample
1
7 3
15

</p>