Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n), b(n);
- for(auto &e: a) cin>>e;
- for(auto &e: b) cin>>e;
- if(count(a.begin(), a.end(), 0)==n || count(b.begin(), b.end(), 0)==n)
- {
- cout<<"Yes\n";
- continue;
- }
- set<int> st;
- for(int i=0; i<n; i++)
- {
- int x=a[i], y=b[i];
- int c = 0, tmp, z;
- if(a[i]==0 && b[i]==0) continue;
- while(x && y)
- {
- if(x <= y)
- {
- z = (y/x);
- c += z+z/2;
- tmp = y;
- y %= x;
- if(z%2) x = tmp - (z-1)*x;
- }
- else
- {
- z = (x/y);
- c += z+(z+1)/2;
- tmp = x;
- x %= y;
- if(z%2) y -= x;
- }
- }
- c += (y == 0);
- st.insert(c%3);
- }
- if(st.size() > 1) cout<<"No\n";
- else cout<<"Yes\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment