#include using namespace std; using ll = long long; constexpr long long MOD = 1000000007; long long power(long long x,long long n){ long long res = 1; while(n > 0) { if(n & 1) res *= x; x *= x; n>>=1; } return res; } int main(){ ll p, k; cin >> p >> k; ll dp[k + 1]; for (ll i = 0; i < k + 1; i++) dp[i] = 0; dp[0] = 1; for (ll i = 0; i < k; i++) { dp[i + 1] += dp[i] * p;//掛け算のとき dp[i + 1] += power(2*p, i)-dp[i]; dp[i + 1] %= MOD; } cout << dp[k] << endl; }