Ankit_132

C

Jul 16th, 2023
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         cin>>n;
  15.  
  16.         vector<int> a(n), b(n);
  17.         for(auto &e: a)     cin>>e;
  18.         for(auto &e: b)     cin>>e;
  19.  
  20.         if(count(a.begin(), a.end(), 0)==n || count(b.begin(), b.end(), 0)==n)
  21.         {
  22.             cout<<"Yes\n";
  23.             continue;
  24.         }
  25.  
  26.         set<int> st;
  27.  
  28.         for(int i=0; i<n; i++)
  29.         {
  30.             int x=a[i], y=b[i];
  31.             int c = 0, tmp, z;
  32.  
  33.             if(a[i]==0 && b[i]==0)      continue;
  34.  
  35.             while(x && y)
  36.             {
  37.                 if(x <= y)
  38.                 {
  39.                     z = (y/x);
  40.                     c += z+z/2;
  41.                     tmp = y;
  42.  
  43.                     y %= x;
  44.  
  45.                     if(z%2)     x = tmp - (z-1)*x;
  46.                 }
  47.                 else
  48.                 {
  49.                     z = (x/y);
  50.                     c += z+(z+1)/2;
  51.                     tmp = x;
  52.  
  53.                     x %= y;
  54.  
  55.                     if(z%2)     y -= x;
  56.                 }
  57.             }
  58.  
  59.             c += (y == 0);
  60.             st.insert(c%3);
  61.         }
  62.  
  63.         if(st.size() > 1)       cout<<"No\n";
  64.         else                    cout<<"Yes\n";
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment