每日一题 第五十二期 Codeforces Round 871 (Div. 4)

D. Gold Rush

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

Initially you have a single pile with n n n 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 6 6 6 and split it into piles of sizes 2 2 2 and 4 4 4, which is valid since 4 4 4 is twice as large as 2 2 2.

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

Input

The first line contains an integer t t t ( 1 ≤ t ≤ 1000 1 \leq t \leq 1000 1t1000) — the number of test cases.

The only line of each test case contains two integers n n n and m m m ( 1 ≤ n , m ≤ 1 0 7 1 \leq n, m \leq 10^7 1n,m107) — the starting and target pile sizes, respectively.

Output

For each test case, output “YES” if you can make a pile of size exactly m m m, 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
inputCopy
11
6 4
9 4
4 2
18 27
27 4
27 2
27 10
1 1
3 1
5 1
746001 2984004
outputCopy
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 4 4 4.

In the second test case, we can perform the following operations: { 9 } → { 6 , 3 } → { 4 , 2 , 3 } \{\color{red}{9}\} \to \{\color{red}{6},3\} \to \{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.

AC代码:

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
//#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=998244353;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e8 + 10;


int t;

bool dfs(int x, int y)
{
	if((x == y)) return true;
	if(x % 3 != 0 || x < y) return false;
	else return (dfs(x / 3, y) || dfs(x * 2 / 3, y));
}
int main()
{
	cin >> t;
	while(t --){
		int a, b;
		cin >> a >> b;
		if(dfs(a, b)) puts("YES");
		else puts("NO");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值