聯系我們 - 廣告服務 - 聯系電話:
您的當前位置: > 關注 > > 正文

【天天新視野】數學書中求多項式系數的問題 編程上怎么辦?

來源:CSDN 時間:2023-02-07 10:12:53

在數學書我們曾經學過求多項式系數的問題吧,但是編程上怎么辦呢?

先給一道例題看看吧 Easy Task

Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))’ to denote its derivation. We use x^n to denote xn. To calculate the derivation of a polynomial, you should know 3 rules: (1) (C)’=0 where C is a constant. (2) (Cx^n)’=C*n*x^(n-1) where n>=1 and C is a constant. (3) (f1(x)+f2(x))’=(f1(x))’+(f2(x))’. It is easy to prove that the derivation a polynomial is also a polynomial.


(資料圖片)

Here comes the problem, given a polynomial f(x) with non-negative coefficients, can you write a program to calculate the derivation of it?

Input

Standard input will contain multiple test cases. The first line of the input is a single integerT (1 <= T <= 1000) which is the number of test cases. And it will be followed byT consecutive test cases.

There are exactly 2 lines in each test case. The first line of each test case is a single line containing an integerN (0 <= N <= 100). The second line contains N + 1 non-negative integers,CN, CN-1, …, C1, C0, ( 0 <= Ci <= 1000), which are the coefficients of f(x).Ci is the coefficient of the term with degree i in f(x). (CN!=0)

Output

For each test case calculate the result polynomial g(x) also in a single line. (1) If g(x) = 0 just output integer 0.otherwise (2) suppose g(x)= Cmx^m+Cm-1x^(m-1)+…+C0 (Cm!=0),then output the integersCm,Cm-1,…C0. (3) There is a single space between two integers but no spaces after the last integer.

Sample Input

3 0 10 2 3 2 1 3 10 0 1 2

Sample Output

0 6 2 30 0 1

這道例題的意思是先給你一個T,然后是有T組測試樣例,然后給你一個n,表示有n+1個數,讓你求多項式的系數,注意,如果n=0,輸出的是0.

下面給代碼嘍

#includeint main(){    int t, n, i, j, a[1000], b[1000];    while(~scanf("%d", &t))    {        for(i=0;i<T;I++) &n);="" scanf(?%d?,="" &a[j]);="" b[j]="a[j]*(n-j);" if(n="=0)" printf(?0?);="" else="" for(j="0;j<=n;j++)" printf(?%d?,="" b[j]);="" if(j!="n-1)" {="" printf(?="" ?);="" printf(?\n?);="" }="" return="" 0;}

責任編輯:

標簽:

相關推薦:

精彩放送:

新聞聚焦
Top 岛国精品在线