hdu 2065 "红色病毒"问题

考虑生成函数
G(x)=(1+x1!+x22!+x33!+x44!)2(1+x22!+x44!)2 G ( x ) = ( 1 + x 1 ! + x 2 2 ! + x 3 3 ! + x 4 4 ! ⋯ ) 2 ∗ ( 1 + x 2 2 ! + x 4 4 ! ⋯ ) 2
考虑 ex=1+x1!+x22!+x33!+x44! e x = 1 + x 1 ! + x 2 2 ! + x 3 3 ! + x 4 4 ! ⋯
ex=1x1!+x22!x33!+x44! e − x = 1 − x 1 ! + x 2 2 ! − x 3 3 ! + x 4 4 ! ⋯
G(x)=e2x+(exex2)2 G ( x ) = e 2 x + ( e x − e − x 2 ) 2
化简可得 G(x)=e2xe2x+e2x+24=e4x+2e2x+14=(1+4x1!+16x22!+64x33!+256x44!)+2(1+2x1!+4x22!+8x33!+16x44!)+14=(14+x1!+4x22!+16x33!+64x44!)+(12+x1!+2x22!+4x33!+8x44!)+14 G ( x ) = e 2 x ∗ e 2 x + e − 2 x + 2 4 = e 4 x + 2 ∗ e 2 x + 1 4 = ( 1 + 4 ∗ x 1 ! + 16 ∗ x 2 2 ! + 64 ∗ x 3 3 ! + 256 ∗ x 4 4 ! ⋯ ) + 2 ∗ ( 1 + 2 ∗ x 1 ! + 4 ∗ x 2 2 ! + 8 ∗ x 3 3 ! + 16 ∗ x 4 4 ! ⋯ ) + 1 4 = ( 1 4 + x 1 ! + 4 ∗ x 2 2 ! + 16 ∗ x 3 3 ! + 64 ∗ x 4 4 ! ⋯ ) + ( 1 2 + x 1 ! + 2 ∗ x 2 2 ! + 4 ∗ x 3 3 ! + 8 ∗ x 4 4 ! ⋯ ) + 1 4
所以综上第 n n 项答案为 4n1+2n1(mod 100) 4 n − 1 + 2 n − 1 ( m o d   100 )
c++代码如下:

#include
#define rep(i,x,y) for(register int i = x ; i <= y; ++ i)
#define repd(i,x,y) for(register int i = x ; i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
    char c;int sign = 1;x = 0;
    do { c = getchar(); if( c == '-' ) sign = -1; }while(!isdigit(c));
    do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
    x *= sign;
}

const int mod = 100;
int ksm(int x,ll y)
{
    int ans = 1;
    while(y)
    {
        if(y&1) ans = ans * x %mod;
        x = x*x %mod;
        y >>= 1;
    }
    return ans;
}

int main()
{
    int t; ll n;

    while(true){
    read(t);
    if(t == 0) break;
    rep(i,1,t)
    {
        read(n);
        printf("Case %d: %d\n",i,(ksm(2,n-1)+ksm(4,n-1))%mod );
    }
    puts("");
    }
    return 0;    
}

你可能感兴趣的:(hdu)