#include <bits/stdc++.h>
using namespace std;
long long w, h, n, ans, a, b, c, d, p = 1000000007;
long long gcd[4010][4010];
int main() {
  int i, j;
  cin >> w >> h;
  w++;
  h++;
  for (i = 0; i <= w; ++i)
    for (j = 0; j <= h; ++j)
      if (i && j)
        gcd[i][j] = i > j ? gcd[i - j][j] : gcd[i][j - i];
      else
        gcd[i][j] = i + j;
  n = w * h % p;
  ans = n * (n - 1) % p * (n - 2) % p;
  a = (w >> 1) * (h >> 1);
  b = (w + 1 >> 1) * (h >> 1);
  c = (w >> 1) * (h + 1 >> 1);
  d = (w + 1 >> 1) * (h + 1 >> 1);
  ans -= a * b % p * c % p * 6 % p;
  ans -= a * b % p * d % p * 6 % p;
  ans -= a * d % p * c % p * 6 % p;
  ans -= d * b % p * c % p * 6 % p;
  ans %= p;
  for (i = 0; i <= w; ++i)
    for (j = 0; j <= h; ++j)
      if (i || j)
        ans = (ans - (gcd[i][j] - 1) * (w - i) * (h - j) * 6 * ((i && j) + 1)) %
              p;
  cout << (ans + p) % p << endl;
}
