#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #define MOD 1000000007 int ri() { int n; scanf("%d", &n); return n; } int solve(int h, int w) { if (h < w) std::swap(h, w); std::vector > pf_table(h + 1); for (int i = 2; i <= h; i++) if (!pf_table[i].first) for (int j = 2; j <= h / i; j++) pf_table[j * i] = {i, j}; int res = ((int64_t) h * (w - 1) + (int64_t) w * (h - 1)) % MOD; for (int i = 1; i < w; i++) { static int facts[30]; int n_fact = 0; for (int cur = i; ; ) { std::pair next = pf_table[cur]; if (!next.first) { if (cur > 1) facts[n_fact++] = cur; break; } facts[n_fact++] = next.first; cur = next.second; } // facts should be sorted in descending order here n_fact = std::unique(facts, facts + n_fact) - facts; int prod[1 << n_fact]; for (int j = 0; j < n_fact; j++) prod[1 << j] = facts[j]; prod[0] = 1; int64_t so_num = 0; int64_t so_sum = 0; for (unsigned int j = 0; j < 1 << n_fact; j++) { int cur = prod[j] = prod[j & j - 1] * prod[j & ~(j - 1)]; int num = (h - 1) / cur; int64_t sum = (int64_t) num * (num + 1) / 2 * cur; if (__builtin_popcount(j) & 1) so_num -= num, so_sum -= sum; else so_num += num, so_sum += sum; } res = (res + (int64_t)(2 * (w - i)) * ((so_num * h - so_sum) % MOD)) % MOD; } return res; } int main() { int h = ri(), w = ri(); std::cout << solve(h, w) << std::endl; return 0; }