import numpy as np #誤差死する n,k = map(int,input().split()) size = k**3 matrix = np.zeros((size, size), dtype = int) for i in range(size): val = i aCount = val % k val = val // k abCount = val % k val = val // k abcCount = val % k #aが追加された時 newACount = (aCount + 1) % k newABCount = abCount newABCCount = abcCount matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1 #bが追加された時 newACount = aCount newABCount = (abCount + aCount) % k newABCCount = abcCount matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1 #cが追加された時 newACount = aCount newABCount = abCount newABCCount = (abcCount + abCount) % k matrix[i, (newABCCount * k + newABCount) * k + newACount] += 1 mod = 1000000007 univ_format = np.frompyfunc(lambda x: x % mod, 1, 1) print(matrix) res = np.zeros((1, k**3), dtype = int) res[0, 0] = 1 def stupidMul(a, b, h, w, size): res = np.zeros((h, w), dtype = int) for i in range(h): for j in range(w): for k in range(size): res[i, j] += a[i, k] * b[k, j] res[i, j] %= mod return res while n > 0: if n % 2 == 1: res = univ_format(stupidMul(res, matrix, 1, size, size)) matrix = univ_format(stupidMul(matrix, matrix, size, size, size)) #print(matrix) #print(matrix.dtype) n = n // 2 numRes = 0 for i in range(k**2): numRes = (numRes + res[0, i]) % mod print(numRes)