Covid Run(Solution)-Codechef October Long Challenge Solution

Input:

Output:

Constraints

Subtasks

Sample Input:

2
6 2 5 3
12 3 4 2

Sample Output:

YES
NO

Explanation:

import java.util.*;
import java.lang.*;
import java.io.*;
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 k = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int j=0;

if(y>n){
System.out.println("NO");
}
else{
for(int i=1;i<=n;i++){
if((x+k*i)%n == y){
System.out.println("YES");
j--;
break;
}
}
}
if(j==0)
System.out.println("NO");
}

}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store