HDU2065 指数型母函数

思路:由指数型母函数的知识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.

#include<cstdio>
#define MOD 100
int pow_mod(int a,__int64 n)
{
    int res=1;
    while(n){
        if(n&1)res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}
int main()
{
    int t;
    unsigned __int64 n;
    while(~scanf("%d",&t),t){
        int cas=1;
        while(t--){
            scanf("%I64u",&n);          
            printf("Case %d: %d
",cas++,(pow_mod(4,n-1)+pow_mod(2,n-1))%100);
        }
        printf("
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/-Unc/p/4255593.html