#include <bits/stdc++.h>
using namespace std;
const int N(4010), MOD(1000000007);
int h, w, ans;
int t[N];
int g[N][N];
int mul(long long a, long long b) { return a * b % MOD; }
int c2(int x) { return x * (x - 1) / 2; }
int gcd(int i, int j) {
  if (g[i][j]) return g[i][j];
  return gcd(j, i % j);
}
int main() {
  scanf("%d%d", &h, &w);
  for (int i = int(2); i < int(w + 1); ++i) t[i] = (t[i - 1] + i / 2) % MOD;
  for (int i = int(1); i < int(w + 1); ++i) g[0][i] = i;
  for (int i = int(1); i < int(h + 1); ++i) g[i][0] = i;
  for (int i = int(1); i < int(h + 1); ++i)
    for (int j = int(1); j < int(w + 1); ++j) g[i][j] = gcd(i, j);
  for (int i = int(0); i < int(h + 1); ++i)
    for (int j = int(0); j < int(w + 1); ++j)
      if (i + j) g[i][j] = c2(g[i][j]) - c2(g[i][j] - 1);
  for (int i = int(1); i < int(w + 1); ++i)
    g[0][i] = (g[0][i] + g[0][i - 1]) % MOD;
  for (int i = int(1); i < int(h + 1); ++i)
    g[i][0] = (g[i][0] + g[i - 1][0]) % MOD;
  for (int i = int(1); i < int(h + 1); ++i)
    for (int j = int(1); j < int(w + 1); ++j)
      g[i][j] = ((g[i][j] + g[i - 1][j]) % MOD +
                 (g[i][j - 1] - g[i - 1][j - 1]) % MOD) %
                MOD;
  int ans = 0;
  for (int i = int(1); i < int(h + 1); ++i) {
    for (int j = int(0); j < int(w + 1); ++j) {
      int oddh = (i + 1) / 2;
      int oddw = w / 2 + 1;
      if (j % 2 == 0) oddw = w + 1 - oddw;
      int odd = mul(oddh, oddw);
      int even = i * (w + 1) - odd;
      int tmp = mul(odd, odd) + mul(even, even);
      tmp = (tmp - i * (w + 1) -
             2 * (g[i][j] + g[i][w - j] - g[i][0] - g[0][j] - g[0][w - j])) %
            MOD;
      ans = (ans + mul(tmp, 3)) % MOD;
    }
    int tmp = (mul(i, t[w]) + mul(i / 2, c2(w + 1) - t[w])) % MOD;
    tmp = mul(tmp, mul(w + 1, 6));
    ans = (ans + tmp) % MOD;
  }
  printf("%d\n", ans);
  return 0;
}
