#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m, Gcd[4100][4100];
long long C(int n, int d) { return d ? ((n + 1) / 2) : (n / 2 + 1); }
int gcd(int x, int y) {
  if (y == 0) return x;
  if (Gcd[x][y]) return Gcd[x][y];
  return Gcd[x][y] = gcd(y, x % y);
}
int main() {
  cin >> n >> m;
  long long ans = 0;
  for (int x = (0); x <= (1); x++)
    for (int y = (0); y <= (1); y++)
      for (int da = (0); da <= (1); da++)
        for (int db = (0); db <= (1); db++)
          for (int dc = (0); dc <= (1); dc++)
            for (int dd = (0); dd <= (1); dd++)
              if (((x + da) * (y + dd) + (x + dc) * (y + db)) % 2 == 0)
                ans = (C(n, da) * C(m, db) * C(n, dc) * C(m, dd) % MOD *
                           C(n, x) * C(m, y) +
                       ans) %
                      MOD;
  for (long long dx = 0; dx <= n; dx++)
    for (long long dy = 0; dy <= m; dy++) {
      long long ret = 0;
      if (dx || dy)
        ret = 6;
      else
        ret = 1;
      ret += max(0, gcd(dx, dy) - 1) * 6;
      ret = ret * ((n - dx + 1) * (m - dy + 1)) % MOD;
      if (dx && dy) ret <<= 1;
      if (ret >= MOD) ret -= MOD;
      ans = ans - ret;
      if (ans < 0) ans += MOD;
    }
  cout << (ans + MOD) % MOD << endl;
  return 0;
}
