#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { ll P, K; cin >> P >> K; vector> dp(K + 1, vector(2, 0)); dp[0][0] = 1; for (int i = 0; i < K; i++) { { //+ dp[i + 1][0] += dp[i][0]; dp[i + 1][0] += dp[i][1]; dp[i + 1][1] += dp[i][1] * (P - 1); dp[i + 1][1] += dp[i][0] * (P - 1); } { // x dp[i + 1][0] += dp[i][0] * P; dp[i + 1][0] += dp[i][1]; dp[i + 1][1] += dp[i][1] * (P - 1); } } cout << dp[K][0].val() << endl; return 0; }