Monday, November 13, 2017

Identical Toys Distribution

Given the number of T identical toys, find the number of ways W to distribute them among N children.

Input Format:
The first line will contain T and N separated by a space.

Output Format:
The first line will contain W. As W can be large, print the answer as modulo 1000000007

Boundary Conditions: 1 <= T, N <= 1000

Example Input/Output 1:
Input:
2 2
Output:
3
Explanation:
The three ways to disribute 2 toys among 2 children are (2,0) (0,2) (1,1)

Solution:
from math import factorial as fc
x,y=[int(i) for i in input().split()]
print((fc(x+y-1)//(fc(x)*fc(y-1)))%1000000007)
Share: