Polynomial Derivative
Time: 1 s
Memory: 128 MB
Memory: 128 MB
Given a polynomial function \(f(x)=x^n\), the derivative of \(f(x)\) is defined by:
\(f(x)=x^n \rightarrow f(x)^\prime=n.x^{n-1}\)
Here is an example:
\(f(x) = 4x^3 + 3x^2\\ f(x)’ = 12x^2 + 6x\)
Note that the derivative of a constant is \(0\). Now write a program that calculates the derivative of a polynomial function.
\(f(x)=x^n \rightarrow f(x)^\prime=n.x^{n-1}\)
Here is an example:
\(f(x) = 4x^3 + 3x^2\\ f(x)’ = 12x^2 + 6x\)
Note that the derivative of a constant is \(0\). Now write a program that calculates the derivative of a polynomial function.
Input
There will be several test cases. Each test case starts with an integer \(T\), indicating the number of terms the polynomial has. The next line describes the polynomial itself, formed by \(T\) terms, each separated by a \(\mathrm{plus}\) or \(\mathrm{minus}\) symbol. The plus/minus symbols will be surrounded by whitespace. Each of the terms will be in the form \(CxE\), where \(C\) and \(E \) represent the coefficients and the exponents, respectively. Note that, the exponent will be omitted if E=1. The variable \(x\) will be omitted if E=0.
Constraint
\(1 \le T \le100\\
2 \le C \le 100\\
2 \le E \le 100\)
Output
For each test case, print the derivative of the given polynomial.
Examples
| Input | Output |
|---|---|
|
2
7x3 + 3x2 3 3x4 + 4x3 + 2x2 2 7x3 + 53 |
21x2 + 6x
12x3 + 12x2 + 4x 21x2 |
Problem Info
| Problem ID | 358 |
| Time Limit | 1000 ms |
| Memory Limit | 131072 KB |
| Moderators | punter |
Statistics
Submit
You need to Login or Registration for submit your solution