跳到正文

个人记录

[HDU2065]"红色病毒"问题

crashed约 4 分钟
原文
文章信息与版本

文章信息

发布
2019年12月30日
收录
2026年5月12日
更新
2026年11月14日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

题目

        点这里看题目。

分析

        母函数入门题。         不难想到如下的函数:

G(x)=(∑k=0∞x2k(2k)!)2(∑k=0∞xkk!)2G(x)=\left(\sum_{k=0}^{\infty}\frac{x^{2k}}{(2k)!}\right)^2\left(\sum_{k=0}^{\infty}\frac{x^k}{k!}\right)^2

        左边是A,CA,C的取值,右边是B,DB,D的取值。然后化式子——

G(x)=(ex+e−x2)2e2xG(x)=\left(\frac{e^x+e^{-x}}{2}\right)^2e^{2x} G(x)=e2x(e2x+e−2x+2)4G(x)=\frac{e^{2x}(e^{2x}+e^{-2x}+2)}{4} G(x)=e4x+2e2x+14G(x)=\frac{e^{4x}+2e^{2x}+1}{4} G(x)=14(1+∑k=0∞(4k+2×2k)xkk!)G(x)=\frac14\left(1+\sum_{k=0}^{\infty}(4^k+2\times2^k)\frac{x^k}{k!}\right)

        所以[xn]G(x)=4n+2×2n4=4n−1+2n−1[x^n]G(x)=\frac{4^n+2\times2^n}{4}=4^{n-1}+2^{n-1}。打点表之后会发现这个数在mod  100\mod 100的意义下是有周期的,直接打表就好了。

代码

C++
#include <cstdio>

typedef unsigned long long ull;

const int mod = 100;
const int MAXSIZ = 105;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar(); int f = 1;
	while( s < '0' || '9' < s ){ f = 1; if( s == '-' ) f = -1; s = getchar(); }
	while( '0' <= s && s <= '9' ){ x = ( x << 3 ) + ( x << 1 ) + s - '0', s = getchar(); }
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ), x = -x; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int a[MAXSIZ];
int tot;

int qkpow( int base, int indx )
{
	int ret = 1;
	while( indx )
	{
		if( indx & 1 ) ( ret *= base ) %= mod;
		( base *= base ) %= mod, indx >>= 1;
	}
	return ret;
}

int main()
{
	a[1] = 2, tot = 1;
	while( true )
	{
		tot ++, a[tot] = ( qkpow( 4, tot - 1 ) + qkpow( 2, tot - 1 ) ) % mod;
		if( a[tot] == a[3] && tot > 3 ) break;
	}
	tot --;
	int T; ull N;
	while( true )
	{
		read( T );
		if( ! T ) break;
		for( int t = 1 ; t <= T ; t ++ )
		{
			read( N );
			if( N <= 2 ) printf( "Case %d: %d\n", t, a[N] );
			else printf( "Case %d: %d\n", t, a[( N - 3 ) % ( tot - 2 ) + 3] );
		}
		puts( "" );
	}
	return 0;
}
原文