#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; #define PI 3.141592653589793 long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main(){ int n, m; cin >> n >> m; ll a[n], b[m]; rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; ll tmp = 0; rep(i, n){ rep(j, m){ ll g = gcd(a[i], b[j]); ll made = b[j]/g - 1; ll ans = 0; //cout << made << endl; ans+=a[i]*b[j]%mod*(b[j]+1)%mod; //cout << ans << endl; ans-=g*g%mod*made%mod*(made+1)%mod; //cout << ans << endl; if(ans<0) ans+=mod; ans%=mod; ans*=modinv(b[j], mod); ans%=mod; tmp+=ans; tmp%=mod; } } cout << tmp << endl; }