fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /*-----------------------------------------MACROS--------------------------*/
  4. #define inf 1000000007
  5. #define loop(i,n) for(int i=0;i<(int)n;i++)
  6. #define iloop(i,n) for(int i=n;i>=1;i--)
  7. #define FOR(i,a,b) for(int i=a;i<b;i++)
  8. #define sz(a) int((a).size())
  9. #define pb push_back
  10. #define pf pop_front
  11. #define all(c) (c).begin(),(c).end()
  12. #define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
  13. #define present(c,x) ((c).find(x) != (c).end())
  14. #define cpresent(c,x) (find(all(c),x) != (c).end())
  15. #define EPS 1e-9
  16. #define ff first
  17. #define ss second
  18. #define gi(n) scanf("%d",&n)
  19. #define gl(n) cin >> n
  20. #define pi(n) printf("%d",n)
  21. #define pl(n) cout << n
  22. #define ps printf(" ")
  23. #define pn printf("\n")
  24. #define dg(n,s); printf("%s %d",s,n)
  25. #define mp make_pair
  26. #define UNVISITED -1
  27. #define EXPLORED 0
  28. #define VISITED 1
  29. /*--------------------------------------------typedefs-------------------------*/
  30. typedef vector<int> vi;
  31. typedef vector<string> vs;
  32. typedef vector< vi > vvi;
  33. typedef pair<int,int> ii;
  34. typedef vector< ii > vii;
  35. typedef long long ll;
  36. typedef vector< ll > vll;
  37.  
  38. /*-----------------------------------Graph helpers------------------*/
  39. int x_disp[]={-1,0,1,0};
  40. int y_disp[]={0,-1,0,1};
  41.  
  42.  
  43.  
  44.  
  45. int main()
  46. {
  47.  
  48. ios_base::sync_with_stdio(false);
  49. int n,m;
  50. cin>>n>>m;
  51.  
  52. vector<int>boy(n,0),girl(m,0);
  53.  
  54. int b,g;
  55. cin>>b;
  56. for(int i=0;i<b;i++)
  57. {
  58. int temp;
  59. cin>>temp;
  60. boy[i]=1;
  61. }
  62. cin>>g;
  63. for(int i=0;i<g;i++)
  64. {
  65. int temp;
  66. cin>>temp;
  67. girl[i]=1;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. for(int i=0;i<1000000;i++)
  74. {
  75. if(boy[i%n] || girl[i%m])
  76. boy[i%n]=girl[i%m]=1;
  77. }
  78.  
  79.  
  80. if(find(all(boy),0)==boy.end() && find(all(girl),0)==girl.end())
  81. cout<<"Yes";
  82. else
  83. cout<<"No";
  84. return 0;
  85. }
Runtime error #stdin #stdout #stderr 0s 3276KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc