import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") h,w = list(map(int, input().split())) m = min(h,w) f = [None]*(m+1) M = 10**9+7 def subh(k): num = h//k return h*num - (k + num*k)*num//2 def subw(k): num = w//k return w*num - (k + num*k)*num//2 for k in range(m, 0, -1): f[k] = subh(k)*subw(k) for i in range(2*k, m+1, k): f[k] -= f[i] f[k] %= M f[k] %= M ans = (f[1]*2 + (h-1)*w + h*(w-1))%M print(ans%M)