poj 3734 Blocks 指数型母函数

递推公式:E(t)=(1+t+t^2/2!+......+..)^2*(1+t^2/2!+t^4/4!+..+)^2
                   =e^2t*((e^t+e^-t)/2)^2
                   =1/4(e^4t+2*e^2t+1)
                   =sigma(1/4*[4^n+2*2^n+1]*t^n/n!) n=0,1,2,,,

  ==> a(n)=1/4(4^n+2*2^n) 

 

/*
* poj3734.c
*
* Created on: 2011-10-11
* Author: bjfuwangzhu
*/

#include<stdio.h>
#define nmod 10007
int modular_exp(int a, int b) {
int res, temp;
res = 1 % nmod,temp = a % nmod;
while (b) {
if (b & 1) {
res = res * temp % nmod;
}
temp = temp * temp % nmod;
b >>= 1;
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int t, n, res;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
res = (modular_exp(4, n - 1) + modular_exp(2, n - 1)) % nmod;
printf("%d\n", res);
}
return 0;
}

你可能感兴趣的:(block)