Note:
(1 + x/1! + X ^ 2/2! + ''+ X ^ n/n !) ^ 2*(1 + x ^ 2/2! + ''') ^ 2
From e ^ x = 1 + x/1! + X ^ 2/2! + '''
Original formula = e ^ (2 * X) * (E ^ x + e ^ (-x)/2) ^ 2
= (1/4) * (E ^ (2 * x) + 1) ^ 2
= (1/4) * (E ^ (4 * x) + 2 * E ^ (2 * x) + 1)
= (1/4) * (SIA (4 ^ N) * (x ^ n/n !) + 2 * SIA (2 ^ N) * (x ^ n/n !) + 1)
We can see from the above formula:
X ^ n/n! The coefficient is (4 ^ n + 2*2 ^ n + 1)/4 = 4 ^ (n-1) + 2 ^ (n-1) + 1/4
For this question, you only need to calculate (4 ^ (n-1) + 2 ^ (n-1) % 100.
In this example, we will not mention the design of the remainder for large numbers. We have used the binary value of the index ~~
/*
* hdu2065.c
*
* Created on: 2011-9-10
* Author: bjfuwangzhu
*/
#include<stdio.h>
#define LL long long
#define nmax 100
int modular_exp(int a, LL b) {
int res;
res = 1;
while (b) {
if (b & 1) {
res = res * a % nmax;
}
a = a * a % nmax;
b >>= 1;
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int t, i;
LL n;
while (scanf("%d", &t) != EOF,t) {
for (i = 1; i <= t; i++) {
scanf("%I64d", &n);
printf("Case %d: %d\n", i,
(modular_exp(4, n - 1) + modular_exp(2, n - 1)) % nmax);
}
printf("\n");
}
return 0;