#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; typedef pair PL; constexpr int mod = 1e9 + 7; int main() { int p, k; cin >> p >> k; vector dp(2, 0); dp[0] = 1; for (int i = 0; i < k; i++) { vector ndp(2, 0); ndp[0] = dp[0] + dp[1]; ndp[0] %= mod; ndp[1] = (dp[0] + dp[1]) % mod; (ndp[1] *= (p - 1)) %= mod; (ndp[0] += (dp[0] * p % mod + dp[1]) % mod) %= mod; (ndp[1] += (dp[1] * (p - 1) % mod)) %= mod; swap(dp, ndp); } cout << dp[0] << endl; return 0; }