#K44282. Candy Distribution Challenge

    ID: 27497 Type: Default 1000ms 256MiB

Candy Distribution Challenge

Candy Distribution Challenge

You are given m candies and k jars. Your task is to determine the number of ways to distribute the candies among the jars. Note that the jars are considered distinct, but the order of candies within each jar does not matter.

The solution is based on the stars and bars theorem. Mathematically, the problem is equivalent to finding the number of nonnegative integer solutions to the equation:

[ x_1 + x_2 + \cdots + x_k = m, ]

which is given by the formula:

[ \binom{m+k-1}{k-1} ]

You need to process multiple datasets. Each dataset consists of two integers k and m (where k ≥ 1 and m ≥ 0). The input terminates with a dataset where both k and m are zero. This terminating dataset should not be processed.

inputFormat

The input consists of multiple lines. Each line contains two space-separated integers k and m.

The input ends with a line containing "0 0", which should not be processed as a test case.

outputFormat

For each dataset (except the terminating one), output the number of distributions (one per line) according to the formula:

[ \binom{m+k-1}{k-1} ]

sample

2 4
3 5
0 0
5

21

</p>