By Ricardo Martins, IFSULDEMINAS Brazil
The calculation of a derivative of a function in the form xn is defined by:
f(x) = xn → f(x)’ = n.xn-1
Here's an example:
f(x) = 4x3 + 3x2 → f(x)’ = 12x2 + 6x
Write a program that, given a simple polynomial, calculate its derivative.
There will be several test cases. Each test case is formed by an integer T, which is the number of terms that has the polynomial. In the next line, there is the polynomial itself, formed by T ( 1 ≤ T ≤ 100) terms, each separated by a space, a sum signal and another space, and each containing an integer C ( 2 ≤ C ≤ 100), the letter x and an integer E ( 2 ≤ E ≤ 100 ), and the coefficient C and E the exponent of the term. The entry ends with end of file.
For each test case, print the polynomial with the derivative applied.
Input Sample | Output Sample |
2 7x3 + 3x2 3 3x4 + 4x3 + 2x2 |
21x2 + 6x 12x3 + 12x2 + 4x |