Sdut 2608-alice and Bob (math problem)

Source: Internet
Author: User

Alice and Bob Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title 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 a integer P, please tell the coefficient of the x^p.

Can you help Bob answer these questions?

Enter the first line of the input is a number T, which means the number of the 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 was 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 all test case, please output the answer Module 2012. Sample input
122 1234
Sample output
20
Tip 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 2013 ACM College Student Program Design competition, Shandong Province
Test instructions: That is to ask you to find the coefficients of the two-item x^p.

Idea: Just find a simple formula to open can see the law, and the binary has a bit of a relationship.

#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 (math problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.