CF1829D Gold Rush

 

>>> /3 -> 遍历一遍就可以了

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
#define ddd printf("-----------------debug\n");
using namespace std;
const int maxn=100000;

int n,m;
bool bfs(int n,int m)
{
    queue<int> q; q.push(n);
    while(!q.empty())
    {
        int u=q.front(); q.pop();
        if(u==m) return 1;
        else if(u<m) continue;
        else if(u%3==0) q.push(u/3),q.push(2*(u/3));
    }
    return 0;
} 
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int T; cin>>T;
    while(T--)
    {
        cin>>n>>m;
        if(bfs(n,m)) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
        
    }
    
    
    return 0;
}
View Code

 

 
 
 
posted @ 2023-08-09 23:19  JMXZ  阅读(14)  评论(0)    收藏  举报