TLE '16 Contest 7 P1 - Math Helper
View as PDF
While the CS nerd is preparing for various computing competitions, the girl approaches him! She gives him some calculus homework and asks him to do it for her help her complete it. Not wanting to waste a valuable opportunity, the CS nerd agrees to help.
The girl takes out a large stapled package of paper with many simple calculus problems. Her task is to take the derivative of each equation on the sheet.
Each equation is in the form y = ax^b, where  and 
 are given integers. The derivative of this equation (more accurately, the derivative of 
 with respect to 
) is 
y' = abx^(b-1). The derivative should also be as simplified as possible. In particular, all these rules must be satisfied:
0x^nshould be simplified to0kx^0should be simplified tok1x^nwhereshould be simplified to
x^n-1x^nwhereshould be simplified to
-x^nkx^1whereshould be simplified to
kx1x^1should be simplified tox-1x^1should be simplified to-xkx^-nwhereshould not be in fraction form (i.e. it should not be
k/(x^n))
A given equation may be in its simplified form as described above.
There are  problems on the worksheet. Can you help the CS nerd finish this tedious homework?
Input Specification
The first line will contain a single integer,  
, the number of problems.
The next  lines of input each contain an equation in the form 
y = ax^b, which could be in a more simplified form, but not completely simplified. It is guaranteed that  and 
.
Output Specification
For each of the  equations, output the derivative on a separate line.
Sample Input
7
y = x^5
y = 2x^2
y = 100
y = -3x^-2
y = 5x
y = -x^10
y = 0x^0
Sample Output
y' = 5x^4
y' = 4x
y' = 0
y' = 6x^-3
y' = 5
y' = -10x^9
y' = 0
Comments