zoukankan      html  css  js  c++  java
  • hdu 2065 "红色病毒"问题 指数型母函数

    由题知:

    (1+x/1!+x^2/2!+``+x^n/n!)^2*(1+x^2/2!+```)^2

    由e^x=1+x/1!+x^2/2!+```知

    原式=e^(2*x)*((e^x+e^(-x))/2)^2

      =(1/4)*(e^(2*x)+1)^2

      =(1/4)*(e^(4*x)+2*e^(2*x)+1)

      =(1/4)*(sia(4^n)*(x^n/n!)+2*sia(2^n)*(x^n/n!)+1)

      由以上式子可知:

      x^n/n!的系数为(4^n+2*2^n+1)/4=4^(n-1)+2^(n-1)+1/4

    对于本题只需要计算(4^(n-1)+2^(n-1))%100即可。

    其中设计大数取余,就不多说了哦,利用了指数的二进制哦~~

    /*
    * hdu2065.c
    *
    * Created on: 2011-9-10
    * Author: bjfuwangzhu
    */

    #include<stdio.h>
    #define LL long long
    #define nmax 100
    int modular_exp(int a, LL b) {
    int res;
    res = 1;
    while (b) {
    if (b & 1) {
    res = res * a % nmax;
    }
    a = a * a % nmax;
    b >>= 1;
    }
    return res;
    }
    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    int t, i;
    LL n;
    while (scanf("%d", &t) != EOF,t) {
    for (i = 1; i <= t; i++) {
    scanf("%I64d", &n);
    printf("Case %d: %d\n", i,
    (modular_exp(4, n - 1) + modular_exp(2, n - 1)) % nmax);
    }
    printf("\n");
    }
    return 0;

  • 相关阅读:
    设计模式之桥接模式(Java语言描述)
    我和CSDN的那些事
    设计模式之合成模式(Java语言描述)
    CAP原理和BASE思想
    finsh初步
    RTT第一个工程
    时钟芯片默认时间
    嵌入式MCU
    RTT工程管理
    反馈及运放基础了解
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/2206589.html
Copyright © 2011-2022 走看看