Value of polynomial
Submissions: 1088   Accuracy:

17.8%

  Difficulty: Easy   Marks: 2

Given a polynomial represented as poly[] and a value x, compute value of the polynomial for given x.  The result should be computed under modulo 109+7.

Input: poly[] = {2, -6, 2, -1}, x = 3
Output: 5
Output is value of 2x3 - 6x2 + 2x - 1 for x = 3

Input: poly[] = {2, 0, 3, 1}, x = 2
Output: 23
Output is value of 2x3 + 3x + 1 for x = 2

Expected time complexity is O(n) where n is number of elements in input array poly[].

Input:

First line contains an integer, the number of test cases 'T' Each test case should contain an integer, size of array 'N' in the first line. In the second line Input the integer elements of the poly[] in a single line separated by space. Element X should be inputted in the third line after entering the elements of array.

Output:

Print the output in a separate lines

Constraints:

1 <= T <= 1000

1 <= N <= 2000

0 <= poly[i] <= 1000

0 <= x <= 1000

Example:

Input:
1
4
1 2 0 4
2

Output:
20

Explanation:
There is one test case that represents polynomial 1*x^3 + 2*x^2 + 0*x^1 + 4*x^0.  The value of this polynomial for x = 2 is 20.

** For More Input/Output Examples Use 'Expected Output' option **

Author: kartik


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.