/* -*- coding: utf-8 -*- * * 2811.cc: No.2811 Calculation Within Sequence - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ /* global variables */ int ts[MAX_N], ss[MAX_N]; /* subroutines */ template T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } int gcdv(int n, int as[]) { int g = 0; for (int i = 0; i < n; i++) g = gcd(g, as[i]); return g; } /* main */ int main() { int a, b; scanf("%d%d", &a, &b); for (int i = 0; i < a; i++) scanf("%d", ts + i); for (int i = 0; i < b; i++) scanf("%d", ss + i); int tg = gcdv(a, ts); int sg = gcdv(b, ss); if (sg % tg == 0) puts("Yes"); else puts("No"); return 0; }