#P5050. Polynomial Evaluation

    ID: 18288 Type: Default 1000ms 256MiB

Polynomial Evaluation

Polynomial Evaluation

You are given a polynomial f(x) of degree n in the form:

\(f(x) = c_0 + c_1 x + c_2 x^2 + \cdots + c_n x^n\)

You are also given m query values \(a_i\) for \(i \in [1, m]\). Your task is to compute \(f(a_i)\) for each query and output the result on a separate line.

inputFormat

The input consists of three lines:

  1. The first line contains two integers n and m, where n is the degree of the polynomial and m is the number of queries.
  2. The second line contains n+1 space-separated integers representing the coefficients \(c_0, c_1, \dots, c_n\) of the polynomial.
  3. The third line contains m space-separated integers \(a_1, a_2, \dots, a_m\) representing the query points.

Note that the polynomial is defined as \(f(x) = c_0 + c_1 x + c_2 x^2 + \cdots + c_n x^n\).

outputFormat

Output m lines. The i-th line should contain the value of \(f(a_i)\).

sample

2 3
1 2 3
0 1 2
1

6 17

</p>