Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水題

B. Magic Stick

Recently Petya walked in the forest and found a magic stick.c++

Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer:app

If the chosen number 𝑎 is even, then the spell will turn it into 3𝑎2; If the chosen number 𝑎 is greater than one, then the spell will turn it into 𝑎−1. Note that if the number is even and greater than one, then Petya can choose which spell to apply.ui

Petya now has only one number 𝑥. He wants to know if his favorite number 𝑦 can be obtained from 𝑥 using the spells he knows. The spells can be used any number of times in any order. It is not required to use spells, Petya can leave 𝑥 as it is.spa

Input

The first line contains single integer 𝑇 (1≤𝑇≤104) — the number of test cases. Each test case consists of two lines.rest

The first line of each test case contains two integers 𝑥 and 𝑦 (1≤𝑥,𝑦≤109) — the current number and the number that Petya wants to get.code

Output

For the 𝑖-th test case print the answer on it — YES if Petya can get the number 𝑦 from the number 𝑥 using known spells, and NO otherwise.ci

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).get

Example

input 7 2 3 1 1 3 6 6 8 1 2 4 1 31235 6578234 output YES YES NO YES NO YES YESinput

題意

如今給你一個數x。 若是這個數是偶數,你能夠讓這個數變成x/2*3。 你也能夠讓這個數變成x-1string

問你x通過若干次變換以後,可否變成y,能輸出YES,不能輸出NO

題解

其實,當x大於等於4的時候,這個x就能夠變成無限大了,而後讓x不斷減1,就能夠獲得y了。 其餘狀況咱們暴力就能夠。

代碼

#include<bits/stdc++.h>
using namespace std;

void solve(){
	long long x,y;
	map<long long,int>H;
	cin>>x>>y;
	while(H[x]==0){
		if(x>=y){
			cout<<"YES"<<endl;
			return;
		}
		H[x]=1;
		if(x%2==1)x--;
		x=x/2*3;
	}
	cout<<"NO"<<endl;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--)solve();
}
相關文章
相關標籤/搜索