#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const long long MAX = 4000 + 10;
long long w, h;
long long sum[MAX], g[MAX][MAX], f[MAX][MAX];
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long chaji(long long a, long long b, long long c, long long d, long long e,
                long long f) {
  return (c - a) * (f - b) - (e - a) * (d - b);
}
int main() {
  long long i, j, k, a, b, c, ans = 0;
  cin >> w >> h;
  for (i = 0; i <= w; ++i)
    for (j = 0; j <= h; ++j) ++sum[(i % 2) * 2 + (j % 2)];
  for (i = 0; i < 4; ++i)
    for (j = 0; j < 4; ++j)
      for (k = 0; k < 4; ++k) {
        if ((chaji(i / 2, i % 2, j / 2, j % 2, k / 2, k % 2)) % 2 == 0) {
          a = sum[i];
          b = sum[j];
          c = sum[k];
          if (i == j && j == k)
            b -= 1, c -= 2;
          else if (i == j)
            --b;
          else if (i == k)
            --c;
          else if (k == j)
            --c;
          ans = (ans + a * b % Mod * c % Mod) % Mod;
        }
      }
  for (i = 1; i <= w; ++i)
    for (j = 1; j <= h; ++j) {
      long long p = gcd(i, j) - 1;
      g[i][j] = (g[i - 1][j] + g[i][j - 1] + Mod - g[i - 1][j - 1] +
                 (p > 0) * p * 6) %
                Mod;
      f[i][j] =
          (f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1] + Mod + g[i][j] * 2) %
          Mod;
    }
  ans = (ans - f[w][h] + Mod) % Mod;
  if (w + 1 >= 3)
    ans = (ans + Mod - (w + 1) * w % Mod * (w - 1) % Mod * (h + 1) % Mod) % Mod;
  if (h + 1 >= 3)
    ans = (ans + Mod - (h + 1) * h % Mod * (h - 1) % Mod * (w + 1) % Mod) % Mod;
  cout << ans << endl;
}
