ACM PKU 3734 Blocks
题目描述:http://poj.org/problem?id=3734
递推公式: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)
=sigma(1/4*[4^n+2*2^n]*t^n/n!) n=0,1,2,,,
==> a(n)=1/4(4^n+2*2^n)
#include <iostream> #include <cstring> #include <cstdio> const int M = 10007; using namespace std; int solve (int t,int k) //快速幂;求的是t的k次幂; { int res=1; while(k) { if(k&1)res=(res*t)%M; t=t*t%M; //这里要取余,不取余会wa k>>=1; } return res; } int main() { //freopen("in.txt","r",stdin); int n,n_case; scanf("%d",&n_case); while(n_case--) { scanf("%d",&n); int ans = solve(2,n-1); ans = ans*(ans+1)%M; printf("%d\n",ans); } return 0; }