编程介的小学生 2016-12-24 07:01 采纳率: 20.5%
浏览 826
已采纳

It's My Derivative

Description

As an unnamed space agency endured the ridicule following their now-infamous metric/English unit conversion, they made a vow to never let that error happen again. Unfortunately, they over-hired poor college students with excellent metric/English unit conversion skills but not calculus skills. In fact, nobody at this agency can now remember how to calculate the derivative of a polynomial, let alone evaluate the derivative of a polynomial for a given value of x.

As any good government agency would do in this case, they've decided to outsource the task...to you. And not only do they want you to do the work, they want you to show how you did each step of your calculation so that they might re-learn the skill.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of input polynomials. Each of the following n lines contain:
a value of x at which the first derivative of the polynomial is to be evaluated;
and the polynomial.
All polynomials are expressed in terms of x, with single-digit integer coefficients (positive or negative) and non-negative single-digit integer powers of x. Polynomials do not contain spaces. Coefficients and powers of 1 (and powers of 0) are omitted from the notation, as is any "+" sign that might apply to the leading term. The leading term has the highest order, and is followed by the one (if any) with the next-highest order and so on.

Output

For each polynomial in the input, output the following lines:
The string "POLYNOMIAL N" where N is 1 for the first polynomial, 2 for the second, etc.;
The polynomial, exactly as in the input;
The first derivative of the polynomial from line 2;
The polynomial in line 3 with x replaced by its value in parenthesis (e.g., if x is 6, "2x^3" becomes "2(6)^3");
The polynomial in step 4 with each term fully evaluated;
and the resulting integer, which is equivalent to f'(x) evaluated at the given value of x.

Sample Input

3
5 2x^7+x^2+3x-9
0 -5x^7+x^3+1
-3 5

Sample Output

POLYNOMIAL 1
2x^7+x^2+3x-9
14x^6+2x+3
14(5)^6+2(5)+3
218750+10+3
218763
POLYNOMIAL 2
-5x^7+x^3+1
-35x^6+3x^2
-35(0)^6+3(0)^2
0+0
0
POLYNOMIAL 3
5
0
0
0
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-24 16:20
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)