n c1 c2 ... cn
The input will come from stdin
.
Here n
is the length of the polynomial and it is followed by n
integers which are the coefficients of the polynomial.
Note that c1
is the constant coefficient (i.e. coefficient of \(x^0\) ).
Output: The product of the two input polynomials, displayed to stdout
, in the format:
c1*x^0 + c2*x^1 + c3*x^2 +
\( \cdots \) + cm*x^m
Here m
is the integer degree of the output polynomial.
While ci
is the \( i^{\textrm{th}} \) coefficient of the product (i.e. the coefficient of \( x^{i-1} \) ).
int
.
4 -1 0 0 1
4 1 0 0 1
Output:
-1*x^0 + 0*x^1 + 0*x^2 + 0*x^3 + 0*x^4 + 0*x^5 + 1*x^6
stdout
.
4 -100 2 3 99
2 1 -2
-4
n1 n2
Here the special polynomials are of the form \( f_n (x) = 1 + 2x + 3x^2 + \cdots + nx^{n-1} \). So if the input was
5 2
then the two polynomials would be \( 1 + 2x + 3x^2 + 4x^3 + 5x^4 \) and \( 1 + 2x \).
stdout
.
5 8
540
A sample environment is available at this IDEONE snippet. It happens to return the correct result for one input. A real algorithm will actually compute something.