1266 Horner tips

Source: Internet
Author: User
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 
     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.