证明:从题目可以知道 A: (1 + x2/1! + x4/2! + ....); B: (1 + x/1! + x2/2! + x3/3! + ...); C:(1 + x2/1! + x4/2! + ....); D: (1 + x/1! + x2/2! + x3/3! + ...);
所以有: G(x) = (1 + x2/1! + x4/2! + ....)2 * (1 + x/1! + x2/2! + x3/3! + ...)2;
由于泰勒展开式:
ex = 1 + x/1! + x2/2! + x3/3! + ...
e-x = 1 - x/1! + x2/2! - x3/3! + ...
所以
G(x) = e2x + ((ex + e-x)/2)2;
= (1/4) * (e2x + 1)2
= (1/4) * (e4x + 2*e2x + 1);
又因为:
e4x = 1 + (4x)/1! + (4x)2/2! + (4x)3/3! + ... + (4x)n/n!;
e2x = 1 + (2x)/1! + (2x)2/2! + (2x)3/3! + ... + (2x)n/n!;
所以:
n次幂的排列数为 (1/4)(4n + 2*2n)
即得所求的解为(1/4)(4n + 2*2n)%100 = (4n-1 + 2n-1)%100;
由组合数学公式 (a + b) % c = (a%c + b%c)%c;
所以可以用快速幂取模求解。
ps:注意精度,用64位。这里WA了一次。
My Code:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int mod = 100;
__int64 exp_mod(int a, __int64 n) {
__int64 t;
if(n == 0) return 1%mod;
if(n == 1) return a%mod;
t = exp_mod(a, n/2);
t = t*t%mod;
if((n&1) == 1) t = t*a%mod;
return t;
}
int main() {
//freopen("data.in", "r", stdin);
int t, cas;
__int64 n;
while(scanf("%d", &t), t) {
cas = 0;
while(t--) {
scanf("%I64d", &n);
printf("Case %d: %I64d\n", ++cas, (exp_mod(4, n-1) + exp_mod(2, n-1))%mod);
}
cout << endl;
}
return 0;
}