#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MID(x,y) ((x+y)>>1)
#define mem(a,b) memset(a,b,sizeof(a))
#define MOD 100
using namespace std;
typedef long long LL;
const int sup = 0x7fffffff;
const int inf = -0x7fffffff;
int PowMod(int a,LL b){
int ret=1;
while(b){
if(b&1)
ret=(ret*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return ret;
}
int main(){
int t;
while(scanf("%d",&t)!=EOF&&t){
int cas=0;
LL n;
while(t--){
scanf("%I64d",&n);
printf("Case %d: %d\n",++cas,(PowMod(4,n-1)+PowMod(2,n-1))%MOD);
}
printf("\n");
}
return 0;
}
转自cxlove:
http://blog.csdn.net/acm_cxlove/article/details/7831009 这篇题解已经解释的很详细了~就不再另写了. 由4种字母组成,A和C只能出现偶数次。 构造指数级生成函数:(1+x/1!+x^2/2!+x^3/3!……)^2*(1+x^2/2!+x^4/4!+x^6/6!……)^2. 前面是B和D的情况,可以任意取,但是相同字母一样,所以要除去排列数。后者是A和C的情况,只能取偶数个情况。 根据泰勒展开,e^x在x0=0点的n阶泰勒多项式为 1+x/1!+x^2/2!+x^3/3!…… 而后者也可以进行调整,需要把奇数项去掉,则e^(-x)的展开式为1-x/1!+X^2/2!-X^3/3!…… 所以后者可以化简为(e^x+e^(-x))/2。则原式为 (e^x)^2 * ((e^x*e^(-x))/2)^2 整理得到1/4*(e^4x+2*e^2x+1)。 又由上面的泰勒展开 e^4x = 1 + (4x)/1! + (4x)^2/2! + (4x)^3/3! + ... + (4x)^n/n!; e^2x = 1 + (2x)/1! + (2x)^2/2! + (2x)^3/3! + ... + (2x)^n/n!; 对于系数为n的系数为(4^n+2*2^n)/4=4^(n-1)+2^(n-1); 快速幂搞之。
转载于:https://www.cnblogs.com/AbandonZHANG/archive/2013/03/17/4114228.html