D. Gold Rush

Initially you have a single pile with nn gold nuggets. In an operation you can do the following:

  • Take any pile and split it into two piles, so that one of the resulting piles has exactly twice as many gold nuggets as the other. (All piles should have an integer number of nuggets.)

One possible move is to take a pile of size 66 and split it into piles of sizes 22 and 44, which is valid since 44 is twice as large as 22.

Can you make a pile with exactly mm gold nuggets using zero or more operations?

Input

The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The only line of each test case contains two integers nn and mm (1≤n,m≤1071≤n,m≤107) — the starting and target pile sizes, respectively.

Output

For each test case, output "YES" if you can make a pile of size exactly mm, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Example

input

 

11

6 4

9 4

4 2

18 27

27 4

27 2

27 10

1 1

3 1

5 1

746001 2984004

output

YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO

Note

The first test case is pictured in the statement. We can make a pile of size 44.

In the second test case, we can perform the following operations: {9}→{6,3}→{4,2,3}{9}→{6,3}→{4,2,3}. The pile that is split apart is colored red before each operation.

In the third test case, we can't perform a single operation.

In the fourth test case, we can't end up with a larger pile than we started with.

思路:

一个数x假设可以除以3

那么这个数可以分成x/3和x/3*2

假设x/3还可以接着往下分的话x/9  x/9*2 |  x/9*2  x/9*2*2

 每次往下分可以分n次的话就可以成上2^0到2^n 用二进制来表示就是这个数可以左移0到n位

#include<iostream>
#include<algorithm>
#include<cstring>//find("string"),rfind("string")
#include<string>//to_string(value)
#include<cstdio>
#include<cmath>
#include<vector>//res.erase(unique(res.begin(), res.end()), res.end())
#include<queue>
#include<stack>
#include<map>
#include<set>//iterator,insert(),erase(),lower/upper_bound(value)/find()return end()
#define ll long long
using namespace std;
signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		bool ok=false;
		if(m==n) ok=true;
		else if(m>n) ok=false;
		else{
			int cnt=0;
			while(n%3==0)
			{
				n/=3;
				cnt++;
				for(int i=0;i<=cnt;i++){
					if(m==n<<i){
						ok=true;
						break;
					}
				}
			}
		}
		if(ok){
			cout<<"YES\n";
		}else{
			cout<<"NO\n";
		}
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值