hdu 2065 "红色病毒"问题

本文探讨了通过生成函数解析组合数列的问题,利用指数函数的幂级数展开形式进行推导,最终给出了一种计算特定数列通项公式的高效方法,并附带提供了C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

考虑生成函数
G(x)=(1+x1!+x22!+x33!+x44!)2(1+x22!+x44!)2G(x)=(1+x1!+x22!+x33!+x44!⋯)2∗(1+x22!+x44!⋯)2
考虑ex=1+x1!+x22!+x33!+x44!ex=1+x1!+x22!+x33!+x44!⋯
ex=1x1!+x22!x33!+x44!e−x=1−x1!+x22!−x33!+x44!⋯
G(x)=e2x+(exex2)2G(x)=e2x+(ex−e−x2)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!)+14G(x)=e2x∗e2x+e−2x+24=e4x+2∗e2x+14=(1+4∗x1!+16∗x22!+64∗x33!+256∗x44!⋯)+2∗(1+2∗x1!+4∗x22!+8∗x33!+16∗x44!⋯)+14=(14+x1!+4∗x22!+16∗x33!+64∗x44!⋯)+(12+x1!+2∗x22!+4∗x33!+8∗x44!⋯)+14
所以综上第nn项答案为4n1+2n1(mod 100)
c++代码如下:

#include<bits/stdc++.h>
#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;    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值