Under construction

Still being built. Things may change

Polynomial and Queries 2

Time limit5sMemory limit512 MB

Summary
Given a degree-N polynomial and K query points, evaluate the polynomial at every point modulo 1,030,307.
Level

Hard8 of 10

Topics
Math, Number theory, Divide and conquer, Brute force
Solved
No attempts yet

Problem

You are given a polynomial f(x)=a0+a1x+a2x2+⋯+aNxNf(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_N x^N of degree NN with integer coefficients.

Given KK integers x1,x2,…,xKx_1, x_2, \ldots, x_K, write a program that computes f(x1),f(x2),…,f(xK)f(x_1), f(x_2), \ldots, f(x_K).

Input

The first line gives the degree of the polynomial, NN. (0≤N≤250,0000 \le N \le 250{,}000)

The second line gives N+1N+1 integers. The ii-th integer is the coefficient ai−1a_{i-1} of the polynomial. (0≤ai<1,030,3070 \le a_i < 1{,}030{,}307)

The third line gives the number of integers, KK. (1≤K≤250,0001 \le K \le 250{,}000)

The fourth line gives x1,x2,…,xKx_1, x_2, \ldots, x_K. (0≤xj<1,030,3070 \le x_j < 1{,}030{,}307)

Output

Print KK lines in total. The ii-th line contains the remainder of f(xi)f(x_i) divided by 1,030,3071{,}030{,}307.

Examples1

  1. Example 1

    Input
    2
    1 2 3
    3
    7 8 9
    
    Expected output
    162
    209
    262