#include <bits/stdc++.h>
using namespace std;
constexpr int N = 4001;
constexpr int64_t M = 1000000007;
int64_t w, h;
int g[N][N];
int64_t pw(int64_t a, int64_t b, int64_t c = M) {
  int64_t ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c;
    b >>= 1;
  }
  return ans;
}
int64_t iv(int64_t x) { return pw(x, M - 2); }
void dfs(int a, int b) {
  if (g[a][b]) return;
  if (!b)
    g[a][b] = a;
  else if (!a)
    g[a][b] = b;
  else {
    int c = a % b;
    dfs(b, c);
    g[a][b] = g[b][c];
  }
}
void work() {
  cin >> w >> h;
  ++w;
  ++h;
  for (int i = 0; i < w; ++i)
    for (int j = !i; j < h; ++j) {
      dfs(i, j);
    }
  int64_t y1 = (w / 2) * (h / 2), y4 = ((w + 1) / 2) * ((h + 1) / 2);
  int64_t y2 = ((w + 1) / 2) * (h / 2), y3 = (w / 2) * ((h + 1) / 2);
  int64_t n = w * h, ans = n * n % M * n % M;
  ans -= y1 * y2 % M * y3 % M * 6;
  ans -= y1 * y2 % M * y4 % M * 6;
  ans -= y1 * y3 % M * y4 % M * 6;
  ans -= y2 * y3 % M * y4 % M * 6;
  ans = (ans % M + M) % M;
  for (int64_t dx = 0; dx < w; ++dx)
    for (int64_t dy = dx ? 1 - h : 1; dy < h; ++dy) {
      int64_t d = g[dx][abs(dy)] + 1;
      int64_t c = (w - dx) * (h - abs(dy));
      ans = (ans - (d - 2) * c * 6) % M;
      ans = (ans - c * 6) % M;
    }
  ans = (ans % M + M - n) % M;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int tc = 1;
  while (tc--) work();
  return 0;
}
