http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608
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?
输入
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
输出
示例输入
1
2
2 1
2
3
4
示例输出
2
0
提示
来源
示例程序
分析:
给出一个多项式:(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1),输入P,求X^p 前边的系数。
将p转换成一个二进制的数,然后分别乘上系数。
AC代码:
1 #include<stdio.h> 2 #include<string.h> 3 int a[55],b[55]; 4 int main() 5 { 6 int t; 7 scanf("%d",&t); 8 while(t--) 9 { 10 int n,p,i,j; 11 scanf("%d",&n); 12 memset(a,0,sizeof(a)); 13 for(i=0;i<n;i++) 14 scanf("%d",&a[i]); 15 scanf("%d",&p); 16 int count,ans; 17 long long c; 18 while(p--) 19 { 20 count=1,ans=0; 21 scanf("%lld",&c); 22 if(c==0) 23 { 24 printf("1\n"); 25 continue; 26 } 27 28 while(c) 29 { 30 b[ans++]=c%2; 31 c/=2; 32 } 33 for(i=0;i<ans;i++) 34 if(b[i]) 35 { 36 count=count*a[i]%2012; 37 } 38 printf("%d\n",count); 39 } 40 } 41 return 0; 42 }