import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10 ** 9 + 7 M,K = map(int, read().split()) def mat_mul(A, B): mask = (1 << 15) - 1 A1 = A >> 15 A2 = A & mask B1 = B >> 15 B2 = B & mask X = np.dot(A1, B1) % MOD Y = np.dot(A2, B2) % MOD Z = (np.dot(A1 + A2, B1 + B2) - X - Y) % MOD return ((X << 30) + (Z << 15) + Y) % MOD def power(A, n): if n == 1: return A B = power(A, n//2) B = mat_mul(B, B) if n & 1: B = mat_mul(A, B) return B A = np.ones((M, M), np.int64) # 加法による遷移 for i in range(M): for j in range(M): j = i * j % M A[j, i] += 1 print(power(A, K)[0,0])