#abc245d. D - Polynomial division

D - Polynomial division

Score : 400400 points

问题描述

我们有一个次数为 NN 的多项式,A(x)=ANxN+AN1xN1++A1x+A0A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0, 和另一个次数为 MM 的多项式,B(x)=BMxM+BM1xM1++B1x+B0B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0

这里,A(x)A(x)B(x)B(x) 的每个系数都是绝对值不大于 100100 的整数,并且首项系数不为 00

同时,令它们的乘积为 $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$。

给定 A0,A1,,ANA_0,A_1,\ldots, A_NC0,C1,,CN+MC_0,C_1,\ldots, C_{N+M},求解 B0,B1,,BMB_0,B_1,\ldots, B_M。 注意,所给输入保证存在唯一的一组序列 B0,B1,,BMB_0, B_1, \ldots, B_M 满足上述条件。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a polynomial of degree NN, A(x)=ANxN+AN1xN1++A1x+A0A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0,
and another of degree MM, B(x)=BMxM+BM1xM1++B1x+B0B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0.
Here, each coefficient of A(x)A(x) and B(x)B(x) is an integer whose absolute value is at most 100100, and the leading coefficients are not 00.

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,,ANA_0,A_1,\ldots, A_N and C0,C1,,CN+MC_0,C_1,\ldots, C_{N+M}, find B0,B1,,BMB_0,B_1,\ldots, B_M.
Here, the given inputs guarantee that there is a unique sequence B0,B1,,BMB_0, B_1, \ldots, B_M that satisfies the given conditions.

Constraints

  • 1N<1001 \leq N < 100
  • 1M<1001 \leq M < 100
  • Ai100|A_i| \leq 100
  • Ci106|C_i| \leq 10^6
  • AN0A_N \neq 0
  • CN+M0C_{N+M} \neq 0
  • There is a unique sequence B0,B1,,BMB_0, B_1, \ldots, B_M that satisfies the conditions given in the statement.

Input

Input is given from Standard Input in the following format:

NN MM

A0A_0 A1A_1 \ldots AN1A_{N-1} ANA_N

C0C_0 C1C_1 \ldots CN+M1C_{N+M-1} CN+MC_{N+M}

Output

Print the M+1M+1 integers B0,B1,,BMB_0,B_1,\ldots, B_M in one line, with spaces in between.

Sample Input 1

1 2
2 1
12 14 8 2

Sample Output 1

6 4 2

For A(x)=x+2A(x)=x+2 and B(x)=2x2+4x+6B(x)=2x^2+4x+6, we have C(x)=A(x)B(x)=(x+2)(2x2+4x+6)=2x3+8x2+14x+12C(x)=A(x)B(x)=(x+2)(2x^2+4x+6)=2x^3+8x^2+14x+12, so B(x)=2x2+4x+6B(x)=2x^2+4x+6 satisfies the given conditions. Thus, B0=6B_0=6, B1=4B_1=4, B2=2B_2=2 should be printed in this order, with spaces in between.

Sample Input 2

1 1
100 1
10000 0 -1

Sample Output 2

100 -1

We have A(x)=x+100A(x)=x+100, C(x)=x2+10000C(x)=-x^2+10000, for which B(x)=x+100B(x)=-x+100 satisfies the given conditions. Thus, 100100, 1-1 should be printed in this order, with spaces in between.

update @ 2024/3/10 10:31:37