http://acm.hdu.edu.cn/showproblem.php?pid=1521
思路:以为是母函数直接求,一看题目发现 maya 不对啊2^64次方,只能去看大牛的题解
母函数f(x)=(1+x/1!+x^2/2!+x^3/3!…+x^n/n!)^2+(1+x^2/2!+x^4/4!+x^6/6!…+…)^2;
泰勒公式:e^x=1+x/1!+x^2/2!+x^3/3!…+x^n/n!;e^(-x)=1-x/1!+x^2/2!-x^3/3!+…-…;
e^x+e^(-x)=1+x^2/2!+x^4/4!+x^6/6!…+…;
f(x)=e^(2x) * ((e^x+e^(-x))/2)^2
= (1/4) * e^(2x) * (e^(2x) + 2 + e^(-2x))
= (1/4) * (e^(4x) + 2*e^(2x) +1)
= (1/4) * ( (1+4x/1!+(4x)^2/2!+(4x)^3/3!+…+(4x)^n/n!) + 2*(1+2x/1!+(2x)^2/2!+(2x)^3/3!+…+(2x)^n/n!) +1)
得: x^n 项系数
a(n) = (1/4) * ((4x)^n/n! + 2*(2x)^n/n!)
= (1/4) * ( 4^n*x^n/n! + 2^(n+1)*x^n/n!)
= (4^(n-1) + 2^(n-1)) * x^n/n!
即所求 F(n) = (4^(n-1) + 2^(n-1)) % 100.
由于 n 比较大 所以要用到快速幂
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long Loli;
Loli Calculation(Loli x, Loli y)
{
Loli resl = 1;
while(y){
if(y & 1){
resl = (resl * x) % 100;
}
x = (x * x) % 100;
y >>= 1;
}
return resl;
}
int main()
{
int Test;
while(cin>>Test && Test)
{
int pos = 0;
while(Test--){
Loli n;
cin>>n;
cout<<"Case "<<++pos<<": ";
if(n == 0){
cout<<"1"<<endl;
}
else{
cout<<(Calculation(2, n-1) + Calculation(4, n-1)) % 100<<endl;
}
}
cout<<endl;
}
return 0;
}