#P3803. Polynomial Multiplication
Polynomial Multiplication
Polynomial Multiplication
Given two polynomials, the first being an \(n\)-th degree polynomial \(F(x)\) and the second an \(m\)-th degree polynomial \(G(x)\), your task is to compute their product.
Formally, if \(F(x)=\sum_{i=0}^{n}a_i x^{n-i}\) and \(G(x)=\sum_{j=0}^{m}b_j x^{m-j}\), then their product is given by:
\[ H(x)=F(x)\cdot G(x)=\sum_{k=0}^{n+m}c_k x^{n+m-k},\quad\text{where}\quad c_k=\sum_{i+j=k}a_i\,b_j. \]Compute and output the coefficients \(c_0, c_1, \ldots, c_{n+m}\) in descending order of power.
inputFormat
The input consists of three lines:
- The first line contains two integers (n) and (m) representing the degrees of the polynomials (F(x)) and (G(x)) respectively.
- The second line contains (n+1) integers representing the coefficients of (F(x)) in descending order of power.
- The third line contains (m+1) integers representing the coefficients of (G(x)) in descending order.
outputFormat
Output a single line containing (n+m+1) integers, which represent the coefficients of the product polynomial (H(x)=F(x)\cdot G(x)) in descending order.
sample
1 1
1 2
3 4
3 10 8