Score : 400 points
Problem Statement
We have a polynomial of degree N, A(x)=ANxN+AN−1xN−1+⋯+A1x+A0,
and another of degree M, B(x)=BMxM+BM−1xM−1+⋯+B1x+B0.
Here, each coefficient of A(x) and B(x) is an integer whose absolute value is at most 100, and the leading coefficients are not 0.
Also, let the product of them be $C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0$.
Given A0,A1,…,AN and C0,C1,…,CN+M, find B0,B1,…,BM.
Here, the given inputs guarantee that there is a unique sequence B0,B1,…,BM that satisfies the given conditions.
Constraints
- 1≤N<100
- 1≤M<100
- ∣Ai∣≤100
- ∣Ci∣≤106
- AN=0
- CN+M=0
- There is a unique sequence B0,B1,…,BM that satisfies the conditions given in the statement.
Input is given from Standard Input in the following format:
N M
A0 A1 … AN−1 AN
C0 C1 … CN+M−1 CN+M
Output
Print the M+1 integers B0,B1,…,BM in one line, with spaces in between.
1 2
2 1
12 14 8 2
6 4 2
For A(x)=x+2 and B(x)=2x2+4x+6, we have C(x)=A(x)B(x)=(x+2)(2x2+4x+6)=2x3+8x2+14x+12, so B(x)=2x2+4x+6 satisfies the given conditions. Thus, B0=6, B1=4, B2=2 should be printed in this order, with spaces in between.
1 1
100 1
10000 0 -1
100 -1
We have A(x)=x+100, C(x)=−x2+10000, for which B(x)=−x+100 satisfies the given conditions.
Thus, 100, −1 should be printed in this order, with spaces in between.