#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 1000000007 using namespace std; typedef pair P; llint p, k; llint dp[100005][2]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> p >> k; dp[0][0] = 1; for(int i = 0; i < k; i++){ for(int j = 0; j < 2; j++){ dp[i+1][0] += dp[i][j], dp[i+1][0] %= mod; dp[i+1][1] += dp[i][j] * (p-1) % mod, dp[i+1][1] %= mod; if(j == 0) dp[i+1][0] += dp[i][j] * p % mod, dp[i+1][0] %= mod; else{ dp[i+1][0] += dp[i][j], dp[i+1][0] %= mod; dp[i+1][1] += dp[i][j] * (p-1) % mod, dp[i+1][1] %= mod; } } } cout << dp[k][0] << endl; return 0; }