fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m;
  4. bool rec(int x){
  5. if(x==m) return 1;
  6. if(x%3) return 0;
  7. return rec(x/3)||rec((x/3)*2);
  8. }
  9. int main() {
  10. ios::sync_with_stdio(0); cin.tie(0);
  11. int t; cin>>t; while(t--){
  12. cin>>n>>m;
  13. if(rec(n)) cout<<"YES"<<'\n';
  14. else cout<<"NO"<<'\n';
  15. }
  16. }
Success #stdin #stdout 0.01s 5292KB
stdin
11
6 4
9 4
4 2
18 27
27 4
27 2
27 10
1 1
3 1
5 1
746001 2984004
stdout
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO