import math n = input() m = n.split() p = [int(i) for i in m] d = 1000000007 / int(p[0]) d = math.ceil(d) f = d * p[0] - 1000000007 h = int(p[1]) / int(d) h = math.floor(h) g = f * h + p[0] * (p[1] - d * h) A = g % 1000000007 print(A)