#include #include const long long MOD = 1e9 + 7; template T gcd(T a, U b){ if(a < b){ a ^= b; b ^= a; a ^= b; } T r; while(b){ r = a % b; a = b; b = r; } return a; } template constexpr T inverse(T a, T m){ T u = 0, v = 1; while(a){ T t = m / a; m -= t * a; std::swap(a, m); u -= t * v; std::swap(u, v); } u %= MOD; if(u < 0) u += MOD; return u; } template constexpr T inverse(T a){ return inverse(a, MOD); } using namespace std; int main(){ int N, M; cin >> N >> M; vector A(N), B(M); for(int i = 0; i < N; i++) cin >> A[i]; for(int j = 0; j < M; j++) cin >> B[j]; long long ans = 0; for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ long long a = A[i], b = B[j]; long long g = gcd(a, b); a /= g; b /= g; ans += a * B[j] % MOD * (B[j] + 1) % MOD * inverse(b) % MOD - (b - 1) * (B[j] / b) % MOD - (B[j] % b + 1) * (B[j] % b) % MOD * inverse(b) % MOD; ans %= MOD; } } cout << (ans + MOD) % MOD << endl; return 0; }