https://vjudge.net/problem/HDU-2065
題意:現在有一長度為N的字符串,滿足一下條件:
(1) 字符串僅由A,B,C,D四個字母組成;
(2) A出現偶數次(也可以不出現);
(3) C出現偶數次(也可以不出現);
計算滿足條件的字符串個數.
當N=2時,所有滿足條件的字符串有如下6個:BB,BD,DB,DD,AA,CC.
由于這個數據肯能非常龐大,你只要給出最后兩位數字即可.
題解:(1+x/1!+x2/2!+x3/3!……)2*(1+x2/2!+x4/4!+x6/6!……)2。題目就是要求出xn/n!的系數。
由泰勒公式(1+x/1!+x2/2!+x3/3!……)2*(1+x2/2!+x4/4!+x6/6!……)^2 = e2x*(1/4)*(ex+e-x)2=1/4(e4x+1+2e2x),再將最后的公式做泰勒展開得到xn/n!的系數為4(n-1)+2^(n-1)

如圖
#include <cstdio>
#include<string.h>
using namespace std;
typedef long long LL;
const LL mod=100;
LL fast_multi(LL a,LL b)
{
LL base=a,res=0;
while(b)
{
if(b&1) res=(res+base)%mod;
b>>=1;
base=(base+base)%mod;
}
return res;
}
LL pow_mod(LL a,LL b)
{
LL base=a,res=1;
while(b)
{
if(b&1) res=fast_multi(res,base);
b>>=1;
base=fast_multi(base,base);
}
return res;
}
int main()
{
int t;
LL n;
while(scanf("%d",&t)!=EOF,t)
{
int cas=1;
while(t--)
{
scanf("%lld",&n);
LL res=(pow_mod(4,n-1)+pow_mod(2,n-1))%mod;
printf("Case %d: %lld\n",cas++,res);
}
printf("\n");
}
return 0;
}