Can_Reach CodeChef Solution

Problem – Can_Reach CodeChef Solution

A first-year student, came to your college. Being a good senior, you must tell him if it is possible to go from College Main Gate to Hostel for him.

The college can be visualized on a 2D-plane. Suppose the College Main Gate is situated at origin i.e. at the coordinates (0,0) and the Hostel is situated at the coordinates (x,y).

As the first-year student wants to explore the college campus further, in one move, he will increase or decrease any coordinate (either the x-coordinate or the y-coordinate) by a value of exactly K.

Is it possible for the first-year student to reach the Hostel?

Input Format

  • First line of input contains a single integer T, denoting the number of test cases. Then the description of the T test case follows.
  • Each test case contains one line of input.
  • The first line contains three integers xyK.

Output Format

For each test case, output a single line answer containing a “YES” or “NO” (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings without quotes “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).


  • 1≤T≤600
  • −1000≤x,y≤1000
  • 1≤K≤1000

Sample 1:

1 2 1
3 -5 2
-9 -6 3
-18 12 5


Test case 1: Here K=1, One of the paths that the first-year student can follow is described as: (0,0) to (1,0) to (1,1) to (1,2). Hence, he can reach the hostel coordinate at (x,y)=(1,2) with the K=1 constraint.

Test case 2: As here K=2, it can be proved that there is no path to move from (0,0) to (3,−5) by only increasing or decreasing any coordinate by exactly K=2.

Test case 3: Here K=3, One of the paths that the first-year student can follow is described as: (0,0) to (−3,0) to (−3,−3) to (−3,−6) to (−6,−6) to (−9,−6). Hence, he can reach the hostel coordinate at (x,y)=(−9,−6) with the K=3 constraint.

Can_Reach CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	    int x,y,k;
	   if (x%k==0 && y%k==0)
	    	cout << "yes" << endl;
	         cout << "no" << endl;    	
	return 0;

Can_Reach CodeChef Solution in Pyth 3

# cook your dish here
for _ in range(int(input())):
    a, b, k = map(int, input().split())
    c = lambda a, b, k: 'YES' if a%k == 0 and b%k == 0 else 'NO'
    print(c(a, b, k))

Can_Reach CodeChef Solution in Java

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

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

/* 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
	    Scanner sc=new Scanner(;
	    int n=sc.nextInt();
	    for(int i=0;i<n;i++){
	        int x=sc.nextInt();
	        int y=sc.nextInt();
	        int k=sc.nextInt();
	        if(x%k==0 && y%k==0)
		// your code goes here
Can_Reach CodeChef Solution Review:

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

Find on CodeChef


I hope this Can_Reach 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 *