#include #define N 3000000 /* \sum_{a,b,gcd(a,b)=1} (h-a)(w-b) f(n) := \sum_{a,b,gcd(a,b)=n} (h-a)(w-b) F(m) := \sum_{a,b,m|gcd(a,b)} (h-a)(w-b) = \sum_{a,m|a}(h-a) \sum_{b,m|b}(w-b) = [h floor(h/m) - m S(floor(h/m))][w floor(w/m) - m S(floor(w/m))] f(1) = \sum_{m} mu(m) F(m) */ const int mod = 1000000007; int h, w; long long int S(int n){ return (long long) n * (n+1) / 2; } int F(int m){ long long a = (long long) h/m*h - (long long) m * S(h/m); long long b = (long long) w/m*w - (long long) m * S(w/m); return (a % mod) * (b % mod) % mod; } int mu[N+1]; int main(){ int i, j; long long int z; mu[1] = 1; for(i=2;i<=N;i++){ if(!mu[i]){ for(j=2*i;j<=N;j+=i){ mu[j] = mu[j]?-mu[j]:-1; } } } for(i=N;i>=1;i--){ if(!mu[i]){ mu[i] = -1; if((long long) i*i > N) continue; for(j=i*i;j<=N;j+=i*i){ mu[j] = 0; } } } scanf("%d%d",&h,&w); z = 0; for(i=1;i<=N;i++){ z += mu[i] * F(i); if(z >= mod) z -= mod; if(z < 0) z += mod; } z += z; z += ((long long) (w-1) * h + (long long) (h-1) * w); z %= mod; printf("%lld\n", z); return 0; }