typedef long long ll; typedef long double ld; #include using namespace std; int main() { ll n,m; std::cin >> n>>m; const ll MOD = 1e9+7; vector a(n),b(m); for (int i = 0; i < n; i++) { std::cin >> a[i]; } for (int i = 0; i < m; i++) { std::cin >> b[i]; } ll ans = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { ll g = gcd(a[j],b[i]); g%=MOD; ans += a[j]%MOD*(b[i]+1)%MOD - (b[i]-g+MOD)%MOD+MOD; } ans %= MOD; } std::cout << ans << std::endl; }