Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Equal Distribution CodeChef Solution

Problem – Equal Distribution CodeChef Solution

Alice and Bob are very good friends and they always distribute all the eatables equally among themselves.

Alice has A chocolates and Bob has B chocolates. Determine whether Alice and Bob can distribute all the chocolates equally among themselves.

Note that:

  • It is not allowed to break a chocolate into more than one piece.
  • No chocolate shall be left in the distribution.

Input Format

  • The first line of input will contain an integer T — the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers A and B, the number of chocolates that Alice and Bob have, respectively.

Output Format

For each test case, output on a new line \texttt{YES}YES if Alice and Bob can distribute all the chocolates equally, else output \texttt{NO}NO. The output is case insensitive, i.e, \texttt{yes}yes, \texttt{YeS}YeS, \texttt{yES}yES will all be accepted as correct answers when Alice and Bob can distribute the chocolates equally.

Constraints

  • 1 \leq T \leq 10001≤T≤1000
  • 1 \leq A, B \leq 10^51≤A,B≤105

Sample 1:

Input: 4
1 1
1 3
1 2
1 4
Output: YES
YES
NO
NO

Explanation:

Test case 1: Both Alice and Bob already have equal number of chocolates, hence it is possible to distribute the chocolates equally among Alice and Bob.

Test case 2: If Bob gives one of his chocolates to Alice, then both of them will have equal number of chocolates, i.e. 2. So, it is possible to distribute the chocolates equally among Alice and Bob.

Test case 3: There are total 3 chocolates. These chocolates cannot be divided equally among Alice and Bob.

Test case 4: Alice and Bob cannot have equal number of chocolates, no matter how they distribute the chocolates.

Equal Distribution CodeChef Solution in Java


import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		    int a=sc.nextInt();
		    int b=sc.nextInt();
		    if(b%2!=0&&a%2!=0||b%2==0&&a%2==0){
		        System.out.println("yes");
		    }else{
		        System.out.println("No");
		    }
		}
	}
}

Equal Distribution CodeChef Solution in Python3

for _ in range(int(input())):
    a,b = map(int,input().split())
    t = a + b
    if t%2 == 0:
        print('Yes')
    else:
        print('No')

Equal Distribution CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        int ans=a+b;
        if(ans%2==0){
            cout << "Yes" <<endl;
        }
        else{
            cout <<"No" <<endl;
        }
    }
	return 0;
}
Equal Distribution CodeChef Solution Review:

In our experience, we suggest you solve this Equal Distribution CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Equal Distribution CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Equal Distribution CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *