Chef and Difficult Contests Codechef Solution

Chef and Difficult Contests Codechef Solution: Oh, these difficult contests… In each contest, there are so many hard tasks Chef cannot solve. However, he knows that he can only become a successful coder if he works hard. Fortunately, he has a problem in mind for training.

You are given two positive integers aa and bb. You may apply the following magical operation any number of times (including zero):

  • choose an arbitrary positive integer dd
  • perform exactly one of the following actions:
    • add dd to aa, add d−1d−1 to bb
    • add d−1d−1 to aa, add dd to bb

Chef is asking you to find out if it is possible to obtain a=ba=b. Help him!

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers aa and bb.

Output

For each test case, print a single line containing the string "YES" if it is possible to obtain a=ba=b or "NO" if it is impossible.

Constraints

  • 1≤T≤1,0001≤T≤1,000
  • 1≤a,b≤1091≤a,b≤109

Subtasks

Subtaks #1 (100 points): original constraints

Sample Input 1 

1
5 7

Sample Output 1 

YES

Explanation

Example case 1: One possible strategy for Chef is:

  • choose d=10d=10, add d−1=9d−1=9 to aa and d=10d=10 to bb; after this operation, a=14a=14 and b=17b=17
  • choose d=10d=10, add d=10d=10 to aa and d−1=9d−1=9 to bb; afterwards, a=24a=24 and b=26b=26
  • choose d=9d=9, add d=9d=9 to aa and d−1=8d−1=8 to bb; afterwards, a=33a=33 and b=34b=34

Chef and Difficult Contests- CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int t;
	    Scanner sc=new Scanner(System.in);
	    t=sc.nextInt();
	    while(t>0){
	        int a,b;
	        a=sc.nextInt();
	        b=sc.nextInt();
	        System.out.println("YES");
	        t--;
	    }
	}
}

Chef and Difficult Contests- CodeChef Solution in CPP

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        cout<<"YES"<<endl;
    }
    return 0;
}

Chef and Difficult Contests-CodeChef Solution in Python

for _ in range(int(input())):
    a,b=map(int,input().split())
    print("YES")

Disclaimer: The above Problem (Chef and Difficult Contests) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose…

Leave a Comment