[HDU2065]"红色病毒"问题
题目
点这里看题目。
分析
母函数入门题。
不难想到如下的函数:
左边是
所以
代码
#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;
}