题目地址:http://codeforces.com/contest/515/problem/B
1 /* 2 无算法,标记和更新happy的人就行了 3 少写一个&!,导致runtime error 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <cmath> 9 #include <algorithm> 10 #include <string> 11 #include <map> 12 #include <vector> 13 #include <set> 14 using namespace std; 15 16 const int MAXN = 1e6 + 10; 17 const int INF = 0x3f3f3f3f; 18 int a[110], b[110]; 19 20 int main(void) 21 { 22 //freopen ("B.in", "r", stdin); 23 24 int n, m; 25 scanf ("%d%d", &n, &m); 26 27 memset (a, 0, sizeof (a)); 28 memset (b, 0, sizeof (b)); 29 30 int x, y, tmp, cnt = 0; 31 scanf ("%d", &x); 32 for (int i=0; i<x; ++i) 33 { 34 scanf ("%d", &tmp); 35 a[tmp] = 1; 36 cnt++; 37 } 38 scanf ("%d", &y); 39 for (int i=0; i<y; ++i) 40 { 41 scanf ("%d", &tmp); 42 b[tmp] = 1; 43 cnt++; 44 } 45 46 for (int i=0; i<=m*n*2; ++i) 47 { 48 if (a[i%n] || b[i%m]) 49 { 50 if (!a[i%n]) cnt++; 51 if (!b[i%m]) cnt++; 52 a[i%n] = b[i%m] = 1; 53 } 54 } 55 (cnt == n + m) ? puts ("Yes") : puts ("No"); 56 57 return 0; 58 }