#include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "STACK:36777216") using namespace std; using i64 = int64_t; constexpr i64 MOD = 1e9 + 7; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); using vi = vector; using vvi = vector; using vvvi = vector; using ii = pair; i64 fact[202020]; i64 factinv[202020]; i64 Ber[10001]; i64 modpow(i64 a, i64 n) { if (n == 0) return 1; if (n % 2 == 0) { i64 t = modpow(a, n / 2); return t * t % MOD; } return a * modpow(a, n - 1) % MOD; } i64 comb(int n, int r); void make() { fact[0] = 1; for (int i = 1; i < 202020; i++) { fact[i] = fact[i - 1] * i % MOD; } for (int i = 0; i < 202020; i++) { factinv[i] = modpow(fact[i], MOD - 2); assert(fact[i] * factinv[i] % MOD == 1); } Ber[0] = 1; for (int i = 1; i < 10001; i++) { i64 tmp = 0; for (int j = 0; j < i; j++) { tmp += comb(i + 1, j) * Ber[j]; tmp %= MOD; } Ber[i] = -1 * modpow(i + 1, MOD - 2) * tmp % MOD; } } i64 comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD; } int main() { make(); i64 ans = 0; i64 n, k; cin >> n >> k; for (int j = 0; j <= k; j++) { ans += comb(k + 1, j) * Ber[j] % MOD * modpow(n + 1, k + 1 - j) % MOD; ans %= MOD; } ans *= modpow(k + 1, MOD - 2); cout << ans % MOD << endl; }