#include <bits/stdc++.h>
using namespace std;
int const mod = 1000000000 + 7;
long long a, b;
long long c[4];
long long f[4009][4009];
long long Mod(int a, int n, int const mod) {
  if (n == 0) return (long long)1;
  long long k = Mod(a, n / 2, mod);
  k = k * k % mod;
  if (n % 2)
    return k * a % mod;
  else
    return k;
}
long long Mul(int i, int k) {
  int x = i / 2, y = i % 2;
  if (x == 0)
    x = (a / 2 + 1);
  else
    x = (a + 1) / 2;
  if (y == 0)
    y = (b / 2 + 1);
  else
    y = (b + 1) / 2;
  long long mul = 0;
  if (k % 2 == i % 2) {
    if (x < 2) return 0ll;
    long long add = 0;
    int z;
    if (k / 2 == 0)
      z = (a / 2 + 1);
    else
      z = (a + 1) / 2;
    mul = y * z % mod;
    mul = mul * x % mod;
    mul = mul * (x - 1) % mod;
    return mul;
  } else if (k / 2 == i / 2) {
    if (y < 2) return 0ll;
    int z;
    if (k / 2 == 0)
      z = (b / 2 + 1);
    else
      z = (b + 1) / 2;
    mul = z * x % mod;
    mul = mul * y % mod;
    mul = mul * (y - 1) % mod;
    return mul;
  }
  return 0ll;
}
int gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
int main() {
  cin >> a >> b;
  long long ans = 0ll;
  for (int i = 0; i < 4; i++) c[i] = 0ll;
  c[0] = (a / 2 + 1) * (b / 2 + 1) % mod;
  c[1] = (a / 2 + 1) * ((1 + b) / 2) % mod;
  c[2] = ((1 + a) / 2) * (b / 2 + 1) % mod;
  c[3] = ((1 + a) / 2) * ((1 + b) / 2) % mod;
  int i, j, k;
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      for (k = 0; k < 4; k++) {
        int flag = 0;
        flag += ((i % 2) ^ (j % 2)) & (((i >> 1) % 2) ^ ((j >> 1) % 2));
        flag += ((i % 2) ^ (k % 2)) & (((i >> 1) % 2) ^ ((k >> 1) % 2));
        flag += ((k % 2) ^ (j % 2)) & (((k >> 1) % 2) ^ ((j >> 1) % 2));
        flag %= 2;
        if (flag == 0) {
          int sum = 0;
          if (i == j) sum++;
          if (j == k) sum++;
          if (i == k) sum++;
          if (sum == 3) sum = 2;
          if (sum == 0) {
            long long add = c[i] * c[j] % mod;
            add = add * c[k] % mod;
            ans = (ans + add) % mod;
          } else if (sum == 1) {
            if (i == j) {
              if (c[i] < 2) continue;
              long long add = c[i] * (c[i] - 1) % mod;
              add = add * c[k] % mod;
              ans = (ans + add) % mod;
            } else if (i == k) {
              if (c[i] < 2) continue;
              long long add = c[i] * (c[i] - 1) % mod;
              add = add * c[j] % mod;
              ans = (ans + add) % mod;
            } else if (j == k) {
              if (c[j] < 2) continue;
              long long add = c[j] * (c[j] - 1) % mod;
              add = add * c[i] % mod;
              ans = (ans + add) % mod;
            }
          } else if (sum == 2) {
            if (c[i] <= 2) continue;
            long long add = c[i] * (c[i] - 1) % mod;
            add = add * (c[i] - 2) % mod;
            ans = (ans + add) % mod;
          }
        }
      }
    }
  }
  for (int i = 1; i <= a + 1; i++)
    for (int j = 1; j <= b + 1; j++) {
      f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
      if (i == 1 && j == 1) continue;
      f[i][j] += gcd(i - 1, j - 1) - 1;
      f[i][j] %= mod;
      long long t = f[i][j] * 2;
      if (i > 2) t -= (i - 2) * (i - 1) / 2;
      if (j > 2) t -= (j - 2) * (j - 1) / 2;
      ans = (ans - t * 6) % mod;
    }
  cout << (ans + mod) % mod << endl;
  return 0;
}
