码迷,mamicode.com
首页 > 其他好文 > 详细

SDUT 2608-Alice and Bob(数学题)

时间:2015-03-28 08:56:34      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

Alice and Bob

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

    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?

输入

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

输出

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

示例输入

122 1234

示例输出

20

提示

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

来源

 2013年山东省第四届ACM大学生程序设计竞赛

题意:就是让你求二项式x^p的系数。

思路:只要随便找个式子化简开就能看出规律,和二进制有点关系。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int mod =2012;
LL a[1010];
int main()
{
    LL T;
    LL n,q;
    LL p;
    LL ans,j,i;
    scanf("%lld",&T);
    while(T--) {
        scanf("%lld",&n);
        memset(a,0,sizeof(a));
        for(i=0; i<n; i++)
            scanf("%lld",&a[i]);
        scanf("%lld",&q);
        while(q--) {
            ans=1;
            j=0;
            scanf("%lld",&p);
            while(p) {
                if(p%2==1) {
                    ans=(ans*a[j])%mod;
                }
                p=p/2;
                j++;
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}


SDUT 2608-Alice and Bob(数学题)

标签:

原文地址:http://blog.csdn.net/u013486414/article/details/44682637

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!