伯努利数
这个是答案
其中的b是伯努利数,可以n^2预处理
伯努利数n^2递推
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e3 + 5, mod = 1e9 + 7; ll n, k; ll inv[N], c[N][N], b[N]; inline ll rd() { ll x = 0, f = 1; char c = getchar(); while(c < ‘0‘ || c > ‘9‘) { if(c == ‘-‘) f = -1; c = getchar(); } while(c >= ‘0‘ && c <= ‘9‘) { x = x * 10 + c - ‘0‘; c = getchar(); } return x * f; } int main() { int T = rd(); c[0][0] = 1; for(int i = 1; i < N; ++i) { c[i][0] = 1; for(int j = 1; j < N; ++j) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } inv[1] = 1; for(int i = 1; i < N; ++i) if(i != 1) inv[i] = (mod - mod / i) * inv[mod % i] % mod; b[0] = 1; for(int i = 1; i < N - 1; ++i) { for(int j = 0; j < i; ++j) b[i] = (b[i] + c[i + 1][j] * b[j]) % mod; b[i] = ((b[i] * -inv[i + 1] % mod) + mod) % mod; } while(T--) { n = rd() % mod; k = rd(); ll ans = 0, fac = 1; for(int i = 1; i <= k + 1; ++i) { fac = fac * (n + 1) % mod; ans = (ans + c[k + 1][i] * b[k + 1 - i] % mod * fac % mod) % mod; } ans = (ans * inv[k + 1]) % mod; printf("%lld\n", ans); } return 0; }