
m = 10^9 + 7 :: Int

modpow :: Int -> Int -> Int
modpow a n
    | n == 1 = a `mod` m
    | otherwise = (if n `mod` 2 == 1
                  then a * modpow (a `mod` m)  (n-1)
                  else modpow (a*a `mod` m) (n `div` 2)) `mod` m

compute a i n k
  | i > n = a
  | otherwise = compute ((a + (i-1) * (modpow (k `div` i) n)) `mod` m) (i+1) n k

main = do
  [n,k] <- map read . words <$> getLine
  print $ (compute (modpow k n) 2 n k) `mod` m