TLE '16 Contest 7 P1 - Math Helper

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem types
A stapled package on simple derivatives - with lots of practice!

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 a and b are given integers. The derivative of this equation (more accurately, the derivative of y with respect to x) is y' = abx^(b-1). The derivative should also be as simplified as possible. In particular, all these rules must be satisfied:

  • 0x^n should be simplified to 0
  • kx^0 should be simplified to k
  • 1x^n where n \ne 0, 1 should be simplified to x^n
  • -1x^n where n \ne 0, 1 should be simplified to -x^n
  • kx^1 where k \ne 0, 1, -1 should be simplified to kx
  • 1x^1 should be simplified to x
  • -1x^1 should be simplified to -x
  • kx^-n where n > 0 should 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 T problems on the worksheet. Can you help the CS nerd finish this tedious homework?

Input Specification

The first line will contain a single integer, T (1 \le T \le 10^5), the number of problems.

The next T 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 |ab| \le 10^9 and -10^9 \le a, b \le 10^9.

Output Specification

For each of the T equations, output the derivative on a separate line.

Sample Input

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


There are no comments at the moment.