CT940

Count Ways to Distribute n Candies Among k Children

EasyAcceptance: 0.0%

In the Candy Shop of Prime City, the Shopkeeper must distribute n identical candies among k children. Each child can receive zero or more candies. By the Stars and Bars theorem, the number of ways is C(n + k - 1, k - 1). "Stars and Bars," the Shopkeeper says. "Place n stars (candies) in a row. Insert k-1 bars to divide them into k groups. The number of arrangements is C(n + k - 1, k - 1), which equals C(n + k - 1, n)." Given n and k, compute the number of ways to distribute n identical candies among k children, modulo 10^9 + 7. Constraints: 0 <= n <= 10^6, 1 <= k <= 10^6 Input: 5 3 Output: 21 Input: 3 2 Output: 4

Constraints:

0 <= n <= 10^6, 1 <= k <= 10^6

Tags:

stars-and-bars combinatorics math
Loading...
Test Cases:No test cases
No test cases available.
Count Ways to Distribute n Candies Among k Children - EASY Coding Problem | CodeTikki