#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import lru_cache H, W = map(int, readline().split()) if H < W: H, W = W, H def S1(n): return n * (n + 1) // 2 def S2(n): return n * (n + 1) * (2 * n + 1) // 6 @lru_cache(None) def f(H, W): """ 1 <= x <= H, 1 <= y <= W, gcd(x,y) = 1 に対して、sum 1, sum x, sum y, sum xyをかえす""" SH = H * (H + 1) // 2 SW = W * (W + 1) // 2 sum_1 = H * W sum_x = SH * W sum_y = SW * H sum_xy = SH * SW d = 2 while True: Hd = H // d Wd = W // d if not Wd: break next_d = min(H // Hd, W // Wd) + 1 s1, sx, sy, sxy = f(Hd, Wd) sum_1 -= s1 * (next_d - d) sum_x -= sx * (S1(next_d - 1) - S1(d - 1)) sum_y -= sy * (S1(next_d - 1) - S1(d - 1)) sum_xy -= sxy * (S2(next_d - 1) - S2(d - 1)) d = next_d return sum_1, sum_x, sum_y, sum_xy sum_1, sum_x, sum_y, sum_xy = f(H, W) answer = sum_1 * H * W - W * sum_x - H * sum_y + sum_xy answer *= 2 # まよこ、まうえ answer += (W - 1) * H answer += (H - 1) * W MOD = 10 ** 9 + 7 print(answer % MOD)