#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include using mint = atcoder::modint1000000007; void solve() { int P, K; cin >> P >> K; mint ans = 1; mint oth = 0; for (int i = 0; i < K; i++) { mint na = 0, no = 0; na += oth * (P - 1) + ans; no += ans + (oth) * (P - 1); na += P * ans + oth * (P - 1); no += oth * (P - 1); ans = na; oth = no; } cout << ans.val() << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }