Uploaded by Jyoti Verma

solve

advertisement
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
map < ll, bool > vis;
bool recurse(ll n, ll &m) {
if(n == m) {
return true;
}
else {
if(n > m and n%3 == 0) {
if(!vis.count(n/3))
vis[n/3] = recurse(n/3,m);
if(!vis.count((n/3)*2))
vis[(n/3)*2] = recurse((n/3)*2,m);
return vis[n/3]||vis[(n/3)*2];
}
return false;
}
}
int main()
{ ios;
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("/Users/sreejith/Desktop/output.txt", "w", stdout);
#endif
ll t;
cin>>t;
while(t--) {
ll n,m;
cin>>n>>m;
vis.clear();
bool res = recurse(n,m);
if(res)
cout<<"YES";
else {
cout<<"NO";
}
cout<<endl;
}
return 0; }
Download