Description
医学界发现的新病毒因其蔓延速度和InternetInternet上传播的”红色病毒”不相上下,被称为”红色病毒”,经研究发现,该病毒及其变种的DNADNA的一条单链中,胞嘧啶,腺嘧啶均是成对出现的。
现在有一长度为NN的字符串,满足一下条件:
(1) 字符串仅由四个字母组成;
(2) AA出现偶数次(也可以不出现);
(3) 出现偶数次(也可以不出现);
计算满足条件的字符串个数.
当N=2N=2时,所有满足条件的字符串有如下66个:.
由于这个数据肯能非常庞大,你只要给出最后两位数字即可.
Input
每组输入的第一行是一个整数TT,表示测试实例的个数,下面是T行数据,每行一个整数,当T=0T=0时结束.
Output
对于每个测试实例,输出字符串个数的最后两位,每组输出后跟一个空行.
Sample Input
4
1
4
20
11
3
14
24
6
0
Sample Output
Case 1: 2
Case 2: 72
Case 3: 32
Case 4: 0
Case 1: 56
Case 2: 72
Case 3: 56
Solution
考虑A,B,C,DA,B,C,D四个字母数量的指数型生成函数
PA(x)=PC(x)=∑i≥01(2i)!x2i=ex+e−x2PA(x)=PC(x)=∑i≥01(2i)!x2i=ex+e−x2,PB(x)=PD(x)=∑i≥01i!xi=exPB(x)=PD(x)=∑i≥01i!xi=ex
故四种字母取若干构成一个排列的生成函数F(x)=P2A(x)⋅P2B(x)=(ex+e−x2)2⋅e2x=e4x+2⋅e2x+14F(x)=PA2(x)⋅PB2(x)=(ex+e−x2)2⋅e2x=e4x+2⋅e2x+14
答案即为n!⋅[xn]F(x)=n!4⋅(4nn!+2⋅2nn!)=4n−1+2n−1n!⋅[xn]F(x)=n!4⋅(4nn!+2⋅2nn!)=4n−1+2n−1,其中[xn]F(x)[xn]F(x)表示F(x)F(x)的xnxn项的系数
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
#define mod 100
int Pow(int a,ll b,int c)
{
int ans=1;
while(b)
{
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
int T,Case;
ll n;
while(scanf("%d",&T),T)
{
Case=1;
while(T--)
{
scanf("%lld",&n);
int ans=Pow(2,n-1,mod);
ans=(ans*ans+ans)%mod;
printf("Case %d: %d\n",Case++,ans);
}
printf("\n");
}
return 0;
}