Codeforces-SolutionsA/Codes/1829 D - Gold Rush/1829D.cpp

30 lines
491 B
C++
Raw Normal View History

2023-06-23 03:53:18 +08:00
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool check(int n,int m)
{
if(n==m) return true;
else if(n%3!=0 || n<m) return false;
else return (check (n/3,m) || check(2*n/3,m));
}
void solve()
{
int n,m;
cin>>n>>m;
bool p=check(n,m);
if(p) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
cin >> TC;
cin.ignore();
while (TC--) solve();
}