# coding:UTF-8 import sys MOD = 10 ** 9 + 7 INF = float('inf') N, M = list(map(int, input().split())) # スペース区切り連続数字 for i in range(1, M+1): base = (N + 1) // i base_plus1_count = (N + 1) - base * i base_count = i - base_plus1_count if base_plus1_count == 0: res = (base-1) * pow(base, base_count-1, MOD) % MOD else: t1 = (base-1) * pow(base, base_count-1, MOD) * pow(base+1, base_plus1_count, MOD) % MOD t2 = pow(base, base_count+1, MOD) * pow(base+1, base_plus1_count-1, MOD) % MOD res = min(t1, t2) print("{}".format(res))