#K59577. Candy Distribution in Identical Jars

    ID: 30895 Type: Default 1000ms 256MiB

Candy Distribution in Identical Jars

Candy Distribution in Identical Jars

You are given (n) distinct candies and (r) identical jars. Your task is to determine the number of ways to distribute all (n) candies into the (r) jars such that no jar remains empty.

The candies are distinct but the jars are identical. One way to solve this problem is by using the recurrence relation:
$$dp[i][j] = dp[i-1][j-1] + dp[i][j-1]$$
where (dp[i][j]) represents the number of ways to distribute (j) candies into (i) jars.

If (n < r), the answer is 0.

inputFormat

The input is read from standard input (stdin) and consists of two space-separated integers (n) and (r), representing the number of candies and the number of jars respectively.

outputFormat

Print a single integer to standard output (stdout) representing the number of ways to distribute the (n) distinct candies into (r) identical jars without leaving any jar empty.## sample

4 2
3