#include using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define let auto const template struct dynarr: std::vector { using std::vector::vector; using size_type = typename std::vector::size_type; auto&& operator[](size_type i) { return this->at(i); } auto&& operator[](size_type i) const { return this->at(i); } }; template struct modint { i64 a; constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {} constexpr i64 value() const noexcept { return a; } constexpr modint& operator+=(const modint r) noexcept { a += r.a; if(a >= M) a -= M; return *this; } constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; } constexpr modint& operator-=(const modint r) noexcept { a -= r.a; if(a < 0) a += M; return *this; } constexpr modint& operator*=(const modint r) noexcept { a = a * r.a % M; return *this; } constexpr modint& operator/=(modint r) noexcept { i64 ex = M - 2; while(ex) { if(ex & 1) { *this *= r; } r *= r; ex >>= 1; } return *this; } constexpr modint operator+(const modint r) const { return modint(*this) += r; } constexpr modint operator-(const modint r) const { return modint(*this) -= r; } constexpr modint operator*(const modint r) const { return modint(*this) *= r; } constexpr modint operator/(const modint r) const { return modint(*this) /= r; } }; const i64 mod = 1e9 + 7; using fp = modint; int main() { i64 H, W; cin >> H >> W; i64 N = max(H, W) + 1; vector a(N), b(N); rep(i,1,H) a[i] = fp(H - i); rep(i,1,W) b[i] = fp(W - i); vector sieve(N, 1); vector prime; rep(p,2,N) { if(sieve[p]) { prime.push_back(p); for(i64 k = 1;k * p < N; ++k) { sieve[k * p] = false; } } } for(auto p: prime) { for(i64 i = (N - 1) / p; i > 0; i--) { a[i] += a[i * p]; b[i] += b[i * p]; } } for(i64 i = 1;i < N;i++) a[i] *= b[i]; for(auto p: prime) { i64 m = (N - 1) / p; for(i64 i = 1; i <= m; i++) { a[i] -= a[i * p]; } } cout << (a[1] * fp(2) + fp(H * (W - 1) + W * (H - 1))).value() << endl; }