Golf CodeChef Solution | LKDNGOLF

Hello coders, today we are going to solve Golf CodeChef Solution whose Problem Code is LKDNGOLF.

Task

It’s a lockdown. You’re bored in your house and are playing golf in the hallway.

The hallway has N+2N+2 tiles numbered from 00 to N+1N+1 from left to right. There is a hole on tile number xx. You hit the ball standing on tile 00. When you hit the ball, it bounces at lengths of kk, i.e. the tiles covered by it are 0,k,2k,…0,k,2k,…, and so on until the ball passes tile N+1N+1.

If the ball doesn’t enter the hole in the first trial, you try again but this time standing on the tile N+1N+1. When you hit the ball, it bounces at lengths of kk, i.e. the tiles covered by it are (N+1),(N+1−k),(N+1−2k),…(N+1),(N+1−k),(N+1−2k),…, and so on until the ball passes tile 00.

Find if the ball will enter the hole, either in its forward journey or backward journey.

Note: The input and output of this problem are large, so prefer using fast input/output methods.

Input

  • The first line contains an integer TT, the number of test cases. Then the test cases follow.
  • The only line of each test case contains three integers N,x,kN,x,k.

Output

Output in a single line, the answer, which should be “YES” if the ball enters the hole either in the forward or backward journey and “NO” if not.

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

Constraints

  • 1≤T≤1051≤T≤10^5
  • 1≤x,k≤N≤10^9

Subtasks

Subtask #1 (10 points): N≤102N≤102

Subtask #2 (90 points): original constraints

Sample Input

3
5 4 2
5 3 2
5 5 2

Sample Output

YES
NO
NO

Explanation

In each test case, the tiles covered by the ball for N=5N=5 and k=2k=2 are {0,2,4,6}{0,2,4,6} in the forward journey and {6,4,2,0}{6,4,2,0} in the backward journey.

Therefore, the answer for the first test case is “YES” since the ball falls in the position of the hole at tile 44. But the answer for test cases 22 and 33 is “NO” since the ball does not fall in the position of the hole.

Solution – Golf CodeChef Solution

Python

# cook your dish here
T = int(input())
for i in range(T):
    N, X, K = map(int, input().split())
    num = (N + 1) % K
    if (X % K == 0 or X % K == num):
        print("Yes")
    else:
        print("No")
    

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
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0){
		    int N = sc.nextInt();
		    int x = sc.nextInt();
		    int k = sc.nextInt();
		    int num = (N+1)%k;
		    if(x%k==0 || x%k==num){
		        System.out.println("YES");
		    }else System.out.println("NO");
		}
	
	}
}

C++

#include <iostream>
using namespace std;

int main() {
    int t;cin>>t;
    while(t--){
        int n,x,k;
        cin >> n >> x >> k;
         int num = (n+1)%k;
		    if(x%k==0 || x%k==num){
		        cout << "YES\n" ;
		    }else cout << "NO\n";
    }
	
	
	return 0;
}

Disclaimer: The above Problem (Golf) is generated by CodeChef but the Solution is provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

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