#include <bits/stdc++.h>
using namespace std;
const int N = 4003, mod = 1e9 + 7;
int m, n, res, x[2], y[2];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
  scanf("%d%d", &m, &n);
  x[1] = (m + 1) / 2;
  x[0] = m + 1 - x[1];
  y[1] = (n + 1) / 2;
  y[0] = n + 1 - y[1];
  for (int x1 = 0; x1 < 2; ++x1)
    for (int x2 = 0; x2 < 2; ++x2)
      for (int x3 = 0; x3 < 2; ++x3)
        for (int y1 = 0; y1 < 2; ++y1)
          for (int y2 = 0; y2 < 2; ++y2)
            for (int y3 = 0; y3 < 2; ++y3) {
              if ((x1 * (y2 + y3) + x2 * (y1 + y3) + x3 * (y1 + y2)) % 2 == 0) {
                res += 1LL * x[x1] * x[x2] % mod * x[x3] % mod * y[y1] % mod *
                       y[y2] % mod * y[y3] % mod;
                res %= mod;
              }
            }
  res += mod - (m + 1) * (n + 1);
  res %= mod;
  res += mod - 3LL * (m + 1) * (n + 1) * ((m + 1) * (n + 1) - 1) % mod;
  res %= mod;
  for (int i = 0; i <= m; ++i)
    for (int j = 0; j <= n; ++j) {
      if (i == 0 && j == 0) continue;
      int d = gcd(i, j);
      int k = 2;
      if (i == 0 || j == 0) k = 1;
      res += mod - 1LL * (m + 1 - i) * (n + 1 - j) * (d - 1) * k * 6 % mod;
      res %= mod;
    }
  printf("%d\n", res);
}
