fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. set< int > happyB;
  8. set< int > happyG;
  9.  
  10. int main(){
  11.  
  12. int x;
  13. int B, G;
  14. int g, b;
  15. bool *boys;
  16. bool *girls;
  17.  
  18. cin >> B >> G;
  19.  
  20. boys= new bool[B];
  21. girls= new bool[G];
  22.  
  23. cin >> b;
  24.  
  25. while( b-- ){
  26.  
  27. cin >> x;
  28. boys[x]= true;
  29. }
  30.  
  31. cin >> g;
  32.  
  33. while( g-- ){
  34.  
  35. cin >> x;
  36. girls[x]= true;
  37. }
  38.  
  39.  
  40. for( int i=0; i<B*G; i++ ){
  41.  
  42. int Gindex= i%G;
  43. int Bindex= i%B;
  44.  
  45. if( boys[Bindex]== true || girls[Gindex]== true ){
  46.  
  47. boys[Bindex]== true;
  48. girls[Gindex]== true;
  49.  
  50. happyB.insert( Bindex );
  51. happyG.insert( Gindex );
  52.  
  53. if( happyG.size()== G && happyB.size()== B ){
  54.  
  55. cout << "Yes";
  56. return 0;
  57. }
  58. }
  59.  
  60. }
  61.  
  62. cout << "No";
  63.  
  64. }
Success #stdin #stdout 0s 3232KB
stdin
2 3
0
1 0
stdout
No