#P1313. Coefficient in the Expansion of \( (by+ax)^k \)
Coefficient in the Expansion of \( (by+ax)^k \)
Coefficient in the Expansion of ( (by+ax)^k )
Given a polynomial of the form \( (by+ax)^k \), your task is to determine the coefficient of the term \( x^n \times y^m \) in its expansion.
The expansion is given by:
\( (by+ax)^k = \sum_{i=0}^{k} \binom{k}{i} (ax)^i (by)^{k-i} = \sum_{i=0}^{k} \binom{k}{i} a^i b^{k-i} x^i y^{k-i} \).
Therefore, the term \( x^n \times y^m \) appears only when \( n+i=\,? \) Actually, note that for the term \( x^n y^m \) we must have \( i=n \) and \( k-i=m \), i.e. \( n+m=k \). If \( n+m\neq k \), then the coefficient is 0.
If \( n+m=k \), the coefficient is given by:
\( \binom{k}{n} a^n b^m \)
inputFormat
Input consists of five space-separated integers: a
, b
, k
, n
, and m
.
They represent the expression \( (by+ax)^k \) and the term \( x^n y^m \) for which you must compute the coefficient.
Note: It is guaranteed that if \( n+m\neq k \), the coefficient should be considered 0.
outputFormat
Output a single integer representing the coefficient of the \( x^n y^m \) term in the expansion of \( (by+ax)^k \).
sample
2 3 3 1 2
54