Description
Horner finds any polynomial p (x) = A0 + A1 * x +... + An * x ^ N can be converted
P (x) = A0 + x * (A1 + x * (A2 +... + X * (an-1 + an * X )...)) To improve the computing efficiency of the computer.
Given the maximum n of p (x), the coefficients a0, A1,..., An, and variable X. Use the Horner method to obtain the polynomial p (x) value.
-
Input
-
There are multiple groups of test data. The first line is an integer T, indicating that there are T groups of test data.
Next, the first behavior of each group of data is two integers x and n. (1 ≤ x ≤ 100, 0 ≤ n ≤ 100000) indicates that the variable value is X, and the maximum number of polynomials is N. The second behavior is n + 1 integer A0, A1,..., An, representing the polynomial coefficient.
-
Output
-
Each group of test data has only one row, and the value of P (x) to 2008 is output.
-
Sample Input
-
32 11 20086 20 1 016 396 177 122
-
Sample output
-
161352
I saw the questions involved in the Article being translated, which is good. For details, refer to this article:
http://blog.csdn.net/jj12345jj198999/article/details/6602500
http://blog.csdn.net/jj12345jj198999/article/details/6604842
# include
using namespace STD; int data [100001]; int main () {int t, x, n, i; long P; CIN> T; while (t --) {CIN> x> N; for (I = 0; I
data [I]; P = data [N]; for (I = N; I> 0; I --) {P = data [I-1] + p * X; If (P> 2008) P = P % 2008;} cout