#include #include #include #include #include #include #include using namespace std; typedef long long ll; const int N_MAX = 3000005; const ll MOD = 1000000007; ll inv[N_MAX],fac[N_MAX],finv[N_MAX]; bool is_prime[N_MAX]; bool skip[N_MAX]; ll cnt[N_MAX]; vector p; void init(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(int i=2;i T gcd(T a, T b) { if (a < b) swap(a, b); while (b != 0) { T tmp = b; b = a % b; a = tmp; } return a; } ll comb(ll n, ll r){ return ((((n%MOD)*((n-1)%MOD))%MOD)*inv[2])%MOD; } ll H, W; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> H >> W; init(); ll ans = 0; for(ll i = 1; i <= max(H, W); i++){ if(skip[i])continue; ll h = H/i, w = W/i; ll rh = H%i, rw = W%i; ll sgn = cnt[i]%2 == 0 ? 1 : -1; // h&w { ll cnt = (rh*rw)%MOD; ll sum = (w*h+h+w+1)%MOD; ll tmp = (comb(sum, 2)*cnt)%MOD; ans += sgn*tmp; } // h { ll cnt = (rh*(i-rw))%MOD; ll sum = (w*h+w)%MOD; ll tmp = (comb(sum, 2)*cnt)%MOD; ans += sgn*tmp; } // w { ll cnt = (rw*(i-rh))%MOD; ll sum = (w*h+h)%MOD; ll tmp = (comb(sum, 2)*cnt)%MOD; ans += sgn*tmp; } // else { ll cnt = ((i-rw)*(i-rh))%MOD; ll sum = (w*h)%MOD; ll tmp = (comb(sum, 2)*cnt)%MOD; ans += sgn*tmp; } ans %= MOD; // cout << i << ' ' << ans << endl; // cout << i << ' ' << ans << ' ' << h << ' ' << w << ' ' << rh << ' ' << rw << ' ' << ((w-rw)*(h-rh)) << endl; } cout << (ans+MOD)%MOD << endl; // ll simple = 0; // for(int i = 0; i < H; i++){ // for(int j = 0; j < H; j++){ // for(int k = 0; k < W; k++){ // for(int l = 0; l < W; l++){ // if(i==j && k==l) continue; // if(gcd(abs(j-i), abs(l-k)) == 1) { // simple++; // } // } // } // } // } // cout << simple/2 << endl; }