Problem F:Alice and Bob
Time Limit: 1000/1000ms (Java/Other) Memory Limit : 65535/32768K(Java/Other)
ProblemDescription
Alice andBob like playing games very much.Today, they introduce a new game.
There isa polynomial like this: (a0*x^(2^0)+1) * (a1 *x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice ask Bob Qquestions. In the expansion of the Polynomial, Given aninteger 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 ofthe 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 thirdline 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, pleaseoutput the answer module 2012.
Sample Input
1
2
2 1
2
3
4
Sample Output
2
0
Hint
The expansion of the (2*x^(2^0) + 1) *(1*x^(2^1) + 1) is 1 + 2*x^1 + 1*x^2 + 2*x^3
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=2012;
long long p;
int que;
int a[55];
int main()
{
freopen("in.in","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
a[n+1]=0;
scanf("%d",&que);
while(que--)
{
cin>>p;
int ans=1;
int st=1;
while(p)
{
if(p&1) ans=(ans*a[st])%mod;
p/=2;st++;
if(st>n+1) break;
}
cout<<ans<<endl;
}
}
return 0;
}