有一个众所周知的公式
[n^m=sumlimits_{i=0}^{m}egin{Bmatrix}m\iend{Bmatrix}i!dbinom{n}{i}
]
注意由于组合数的存在,上限可以改为(n)
[n^m=sumlimits_{i=0}^{n}egin{Bmatrix}m\iend{Bmatrix}i!dbinom{n}{i}
]
此时可以二项式反演
[egin{Bmatrix}m\nend{Bmatrix}n!=sumlimits_{i=0}^{n}(-1)^{n-i}dbinom{n}{i}n^m
]
带入题目中的式子得到
[sumlimits_{i=0}^{n}sumlimits_{j=0}^{n}2^jsumlimits_{k=0}^{j}(-1)^{j-k}dbinom{j}{k}k^i
]
[sumlimits_{j=0}^{n}2^jsumlimits_{k=0}^{j}(-1)^{j-k}dbinom{j}{k}sumlimits_{i=0}^{n}k^i
]
发现(a_k=sumlimits_{i=0}^{k}k^i)是等比数列求和,非常好算
[sumlimits_{j=0}^{n}2^jsumlimits_{k=0}^{j}(-1)^{j-k}dbinom{j}{k}a_k
]
后面一项是卷积,可以(O(nlogn))求解了,但是还能优化
[sumlimits_{k=0}^{n}a_ksumlimits_{j=k}^{n}2^j(-1)^{j-k}dbinom{j}{k}
]
[sumlimits_{k=0}^{n}a_k2^ksumlimits_{j=k}^{n}(-2)^{j-k}dbinom{j}{k}
]
设(q=-2),令(b_j=sumlimits_{i=j}^{n}dbinom{i}{j}q^{i-j})
易得(b_0=2^nfrac{q^{n+1}-1}{q-1}),考虑递推
[b_j-b_{j-1}=sumlimits_{i=j}^{n}dbinom{i}{j}q^{i-j}-sumlimits_{i=j-1}^{n}dbinom{i}{j-1}q^{i-j+1}
]
令第二个式子(i=i+1)
[=sumlimits_{i=j}^{n}dbinom{i}{j}q^{i-j}-sumlimits_{i=j}^{n+1}dbinom{i-1}{j-1}q^{i-j}
]
[=sumlimits_{i=j}^{n}dbinom{i}{j}q^{i-j}-sumlimits_{i=j}^{n}dbinom{i-1}{j-1}q^{i-j}-dbinom{n}{j-1}q^{n-j+1}
]
[=sumlimits_{i=j}^{n}(dbinom{i}{j}-dbinom{i-1}{j-1})q^{i-j}-dbinom{n}{j-1}q^{n-j+1}
]
[=sumlimits_{i=j}^{n}dbinom{i-1}{j}q^{i-j}-dbinom{n}{j-1}q^{n-j+1}
]
单独看(sumlimits_{i=j}^{n}dbinom{i-1}{j}q^{i-j}),令(i=i-1)
[sumlimits_{i=j}^{n}dbinom{i-1}{j}q^{i-j}s=sumlimits_{i=j-1}^{n-1}dbinom{i}{j}q^{i-j+1}
]
[=qsumlimits_{i=j-1}^{n-1}dbinom{i}{j}q^{i-j}
]
[=q(b_j-dbinom{n}{j}q^{n-j})
]
所以
[b_j-b_{j+1}=qb_j-dbinom{n}{j}q^{n-j+1}-dbinom{n}{j-1}q^{n-j+1}
]
[b_j-b_{j+1}=qb_j-dbinom{n+1}{j}q^{n-j+1}
]
[b_j=frac{b_{j-1}-dbinom{n+1}{j}q^{n-j+1}}{1-q}
]
就可以(O(n))递推(b_i)了,线性筛(i^k)之后就可以(O(n))求出(a_k)