Chef vs Doof Codechef Solution

Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has NN integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all NN numbers that he has with him. Find if it is possible for Chef to prevent Dr Doof from destroying the even numbers.

Formally, given NN positive integers, find if there exists an odd number which is an integer multiple of all the given NN numbers. If yes, print “YES”, otherwise “NO”. You can print any letter in any case.

Input

  • First line contains TT, number of testcases. Each testcase consists of 22 lines.
  • The first line of each test case consists of a positive integer NN, denoting the number of positive integers Chef has.
  • The second line of each test case contains NN space separated integers AiAi each denoting an integer that Chef has with him.

Output

For every test case, if there exists such an odd number, print “YES” on a separate line, otherwise “NO”. The judge is case insensitive. That means, your code can print any letter in any case ( “Yes”“yes” or “YES” are all accepted).

Constraints

  • 1≤T≤1031≤T≤103
  • 1≤N≤1031≤N≤103
  • 1≤Ai≤1031≤Ai≤103

Sample Input

2
5
1 2 5 4 3
1
7

Sample Output

NO
YES

Explanation

For test 11: There exists no odd number.

For test 22: The possible odd numbers can be 77, 2121, 4949, 315315, …

Chef vs Doof  – 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(),flag=0;
		    int a[] = new int[n];
		    for(int i=0;i<n;i++)
		    {
		    a[i]=sc.nextInt();
		       if(a[i]%2==0)
		       flag=1;
		    }
		    if(flag==0)
		    System.out.println("YES");
		    else
		     System.out.println("NO");
		}
	}
}

Chef vs Doof  – CodeChef Solution in CPP

#include <iostream>
using namespace std;

int main() {
	int t;cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    int p=1;
	    for(int i=0;i<n;i++){
	        p=p*a[i];
	    }
	    if(p%2==0){
	        cout<<"NO"<<endl;
	    }
	    else{
	        cout<<"YES"<<endl;

	    }
	}
	return 0;
}

Chef vs Doof  -CodeChef Solution in Python

for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    for i in range(0,len(a)):
        if(a[i]%2==0):
            c="No"
            break
        else:
            c="Yes"
    print(c)

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

Leave a Reply

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