import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N,K = mi() mod = 10**9 + 7 inv = 0 for inv in range(1,N+1): if inv*2 % N == 1: break for i in range(N): if N%2==0: if i%2==0: print(0) else: amari = (pow(2,K,N//2)-1) % (N//2) t = ((pow(2,K,N)-1+i)) % N t //= 2 if t <= amari: q = (pow(2,K,mod)-1-amari) % mod else: q = (pow(2,K,mod)-1-amari-(N//2)) % mod ans = (q * pow(N//2,mod-2,mod) + 1) % mod ans *= pow(2,K*(mod-2),mod) ans %= mod print(ans) else: amari = (pow(2,K,N)-1) % N t = ((pow(2,K,N)-1)+i) * inv % N if t <= amari: q = (pow(2,K,mod)-1-amari) % mod else: q = (pow(2,K,mod)-1-amari-N) % mod ans = (q * pow(N,mod-2,mod) + 1) % mod ans *= pow(2,K*(mod-2),mod) ans %= mod print(ans)