#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef pair LP; typedef vector vec; typedef long double ld; typedef pair LDP; const ld eps = 1e-5; const ld pi = acos(-1.0); const int sz = 3000001; bool isp[sz]; bool ign[sz]; int rem[sz]; void init() { fill(isp + 2, isp + sz, true); Rep(i,2, sz) { if (!isp[i])continue; rem[i] = 1; for (int j = 2 * i; j < sz; j += i) { isp[j] = false; rem[j] ^= 1; if ((j%i) % i == 0)ign[j] = true; } } } void solve() { ll h, w; cin >> h >> w; ll ans = 0; //片方0 ans += (h - 1)*w + (w - 1)*h; ans %= mod; for (ll g = 1; g <= min(h - 1, w - 1); g++) { if (ign[g])continue; int th = (h - 1) / g; int tw = (w - 1) / g; ll lep = 0; ll rip = 0; rep1(i, th)lep += h - i * g; rep1(i, tw)rip += w - i * g; lep %= mod; rip %= mod; ll csum = 2 * lep*rip%mod; if (rem[g]) { ans -= csum; } else { ans += csum; } } ans = (ans%mod + mod) % mod; cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(50); init(); solve(); //cout << "finish" << endl; //stop return 0; }