# 【解析】Alice and Bob_24行代码AC

## 立志用最少的代码做最高效的表达

Alice and Bob like playing games very much.Today, they introduce a new game.

There is a polynomial like this: (a0x(20)+1) * (a1 * x(21)+1)…*(an-1 * x(2(n-1))+1). Then Alice ask Bob Q questions. In the expansion of the Polynomial, Given an integer P, please tell the coefficient of the x^P.

Can you help Bob answer these questions?

Input
The first line of the input is a number T, which means the number of the test cases.

For each case, the first line contains a number n, then n numbers a0, a1, … an-1 followed in the next line. In the third line is a number Q, and then following Q numbers P.

1 <= T <= 20
1 <= n <= 50
0 <= ai <= 100
Q <= 1000
0 <= P <= 1234567898765432

Output
For each question of each test case, please output the answer module 2012.

Sample Input
1
2
2 1
2
3
4
Sample Output
2
0

#### 解析

( a 0 ∗ x + 1 ) ∗ ( a 1 ∗ x 2 + 1 ) ∗ ( a 2 ∗ x 4 + 1 ) = a 0 a 1 a 2 ∗ x 7 + a 1 a 2 ∗ x 6 + a 0 a 2 ∗ x 5 + a 2 ∗ x 4 + . . . (a_0*x+1)*(a_1*x^2+1)*(a_2*x^4+1)=a_0a_1a_2*x^7+a_1a_2*x^6+a_0a_2*x^5+a_2*x^4+...

#include<bits/stdc++.h>
using namespace std;
typedef long long gg;
gg a[100];
int main() {
int T; cin >> T; while(T--) {
memset(a, 0, sizeof(a));
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];

int q; cin >> q;
for(int i = 0; i < q; i++) {
gg sum = 1, k = 0;		//存放结果
gg p; cin >> p;

while(p) {
if(p%2 == 1)
sum = (sum*a[k])%2012;
k++;
p /= 2;
}
cout << sum << '\n';
}
}
return 0;
}


06-13 949

10-07 299
08-15 4905
04-20 34
08-12 186
08-01 334
08-23 36
09-23 3203
02-28 1070
03-30 1422
11-29 42
02-13 1032
04-10 1468
06-21 1347