本文主要是介绍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 ! ⋯
e−x=1−x1!+x22!−x33!+x44!⋯ e − x = 1 − x 1 ! + x 2 2 ! − x 3 3 ! + x 4 4 ! ⋯
则 G(x)=e2x+(ex−e−x2)2 G ( x ) = e 2 x + ( e x − e − x 2 ) 2
化简可得 G(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 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 项答案为
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;
}
这篇关于hdu 2065 红色病毒问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!