Hrbust 2052 Alice and Bob【煞笔题啊】

Alice and Bob
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 37(17 users)Total Accepted: 13(13 users)Rating: Special Judge: No
Description

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

There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+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
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

Source
HCPC2014校赛训练赛 2

题目大意:

给你a0~an-1,让你输出x^p前边的系数。


思路:


随便写一组数据:(a0*x+1)*(a1*x^2+1)*(a2*x^4+1)

再算出前四个高位的系数:

a0a1a2*x^7.

a1a2*x^6

a0a2*x^5

ax*x^4

不难观察出,其实x^p的系数,就是按二进制位数取1的位子上相乘的值。


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long int
#define mod 2012
ll a[550];
int main()
{
    ll t;
    scanf("%lld",&t);
    while(t--)
    {
        ll n;
        scanf("%lld",&n);
        memset(a,0,sizeof(a));
        for(ll i=0;i<n;i++)scanf("%lld",&a[i]);
        ll q;
        scanf("%lld",&q);
        while(q--)
        {
            ll output=1;
            ll cnt=0;
            ll x;
            scanf("%lld",&x);
            while(x)
            {
                ll tmp=x%2;
                if(tmp==1)
                {
                    output*=a[cnt];
                    output%=mod;
                }
                x/=2;
                cnt++;
            }
            printf("%lld\n",output);
        }
    }
}










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值