constint p = 1000000007; inlineintadd(int x, int y){ return (x += y) >= p ? x - p : x; } inlineintmul(int x, int y){ return1ll * x * y % p; } intpow_mod(int x, int n){ int s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; }
cin >> n >> m; int ans = 1, inv = pow_mod(m, p - 2); for (int i = 0; i < n; ++i) ans = add(ans, pow_mod(add(2, p - inv), i)); cout << mul(ans, pow_mod(m, n)) << "\n"; return0; }