Chef and Chocolate Codechef Solution

Chef and Chocolate Codechef Solution: Chef has a standard chocolate of n by m pieces. More formally, chocolate is a rectangular plate consisting of n rows and m columns.

Here you can see an example of a standard 5 by 7 chocolate.

Chef and Chocolate Codechef Solution

He has two friends and they will play with this chocolate. First friend takes the chocolate and cuts it into two parts by making either a horizontal or vertical cut. Then, the second friend takes one of the available pieces and divides into two parts by either making a horizontal or vertical cut. Then the turn of first friend comes and he can pick any block of the available chocolates and do the same thing again. The player who cannot make a turn loses.

Now Chef is interested in finding which of his friends will win if both of them play optimally. Output “Yes”, if the friend who plays first will win, otherwise print “No”.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The only line of each test case contains two space separated integers n and m – the sizes of the chocolate.

Output

For each test case, output a single line containing one word “Yes” (without quotes) if there is a sequence of moves leading to the winning of the person who moves first and “No” (without quotes) otherwise.

Constraints

  • 1 ≤ T ≤ 100
  • 1 ≤ n, m ≤ 109

Subtasks

Subtask #1 (10 points):

  • 1 ≤ n, m ≤ 10

Subtask #2 (30 points):

  • n = 1 or m = 1

Subtask #3 (60 points): No additional constraints

Example

Input:
2
1 2
1 3
Output:
Yes
No

Explanation

Example case 1. There is only one possible move, so the second player even won’t have a chance to make move.

Example case 2. There are only two ways first player can make first move, after each of them only one move left, so the first player cannot win.

Chef and Chocolate  – 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
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		    int n=sc.nextInt();
		    int m=sc.nextInt();
		    int pro=n*m;
		    if(pro%2==0){
		        System.out.println("Yes");
		    }
		    else{
		        System.out.println("No");
		    }
		}
	}
}

Chef and Chocolate  – CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    int n,m;
	    cin>>n>>m;
	    if((n*m)%2==0)
	    {
	        cout<<"Yes\n";
	    }
	    else
	        cout<<"No\n";
	}
	return 0;
}

Chef and Chocolate -CodeChef Solution in Python

total_testcases = int(input())
for testcase in range(total_testcases):
    n, m = map(int, input().split())
    if (n * m) % 2 == 0:
        print("Yes")
    else:
        print("No")

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

Leave a Comment