MOD = 10 ** 9 + 7 def matpow(A, B, w): l = len(A) while w: if w & 1: C = [0] * l for i in range(l): for j in range(l): C[i] += A[i][j] * B[j] C[i] %= MOD B = C C = [[0] * l for _ in range(l)] for i in range(l): for j in range(l): for k in range(l): C[i][j] += A[i][k] * A[k][j] C[i][j] %= MOD A = C w >>= 1 return B m, k = map(int, input().split()) B = [0] * m B[0] = 1 A = [[0] * m for _ in range(m)] for i in range(m): for j in range(m): A[(i + j) % m][j] += 1 A[(i * j) % m][j] += 1 B = matpow(A, B, k) print(B[0])