Candy Distribution CodeChef Solution

Problem – Candy Distribution CodeChef Solution

Chef has NN candies. He has to distribute them to exactly MM of his friends such that each friend gets equal number of candies and each friend gets even number of candies. Determine whether it is possible to do so.

NOTE: Chef will not take any candies himself and will distribute all the candies.

Input Format

  • First line will contain TT, number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, two integers NN and MM, the number of candies and the number of friends.

Output Format

For each test case, the output will consist of a single line containing Yes if Chef can distribute the candies as per the conditions and No otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings yesYesyEs, and YES will all be treated as identical).

Constraints

  • 1 \leq T \leq 10001≤T≤1000
  • 1 \leq N,M \leq 10001≤N,M≤1000

Sample 1:

Input: 4
9 3
4 1
4 2
8 3

Output: 
No
Yes
Yes
No

Explanation:

Test case 1: Since Chef has 99 candies and 33 friends, each friend will get \frac{9}{3} = 339​=3 candies. Since 33 is not even, Chef doesn’t satisfy the conditions.

Test case 2: Since Chef has 44 candies and 11 friend, each friend will get \frac{4}{1} = 414​=4 candies. Since 44 is even, Chef satisfies all the conditions.

Test case 3: Since Chef has 44 candies and 22 friends, each friend will get \frac{4}{2} = 224​=2 candies. Since 22 is even, Chef satisfies all the conditions.

Test case 4: Since Chef has 88 candies and 33 friends. Since Chef won’t be able to distribute all the candies equally, Chef does not satisfy all the conditions.

Candy Distribution CodeChef Solution in Java

/* package codechef; // don't place package name! */

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();
		for(int i=0;i<t;i++){
		    int a=sc.nextInt();
		    int b=sc.nextInt();
		    int c=a/b;
		    if(c%2==0 && a%b==0){
		        System.out.println("Yes");
		    }
		    else{
		        System.out.println("No");
		    }
		}
	}
}

Candy Distribution CodeChef Solution in C++14

#include <iostream>
using namespace std;

int main() {
	int t;
    cin>> t;
    
    for(int i = 0; i < t; i++){
        int N, M;
        cin >> N >> M;
        
        if((N%M) == 0 && (N/M)%2 == 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
	return 0;
}

Candy Distribution CodeChef Solution in Python3

for _ in range(int(input())):
    n, m = map(int,input().split())
    if n/m % 2 == 0:
        print ("Yes")
    else:
        print ("No")
Candy Distribution CodeChef Solution Review:

In our experience, we suggest you solve this Candy 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 Candy Distribution CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Candy 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.