指数型母函数的经典题。
在泰勒公式中,令x0 = 0,得到麦克劳林级数:
e^x = 1 + x/1! + x^2/2! + x^3/3! + ... (1)
令x = -x,可得:
e^-x = 1 - x/1! + x^2/2! - x^3/3! + ... (2)
(1)(2)式相加,即可得到所有偶数项,即:
(e^x + e^-x) / 2 = 1 + x^2/2! + x^4/4! + x^6/6! + ...
原题可构造指数型母函数(1 + x/1! + x^2/2! + x^3/3! + ...)^2 * (1 + x^2/2! + x^4/4! + x^6/6! + ...)^2
即(e^x)^2 * ((e^x + e^-x) / 2)^2
化简一下得(e^4x + 2 * e^2x + 1) / 4
对该式进行泰勒展开,并取其中x的指数为n的项的系数,得:4^(n-1) + 2^(n-1)
此即所求的答案
#include <cstdio> #define ll long long const int mod = 1000000007; ll pow_mod(ll x, int y) { ll ret = 1; while (y) { if (y&1) ret = ret * x % mod; x = x * x % mod; y >>= 1; } return ret; } int main() { int n; while (scanf("%d", &n) == 1) { printf("%lld\n", (pow_mod(4, n-1) + pow_mod(2, n-1)) % mod); } return 0; }
这题和hdu2065一模一样,而且我很久之前就A过= =
写下来备忘一下= =