# Need a proper explanation

The topic is Equilize AB

``````		int t = s.nextInt();
while(t-- > 0)
{
int a = s.nextInt();
int b = s.nextInt();
int x = s.nextInt()*2;
if(a == b || Math.abs(a-b) % x == 0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
``````

This is my solution in java. So let’s say you have 4 3 1: you can either do (4+1 and 3-1) or (4-1 and 3+1). This means that there will always be 2 times the difference between those numbers, so that’s why I put `x=x *2` so `1 * 2` becomes `2`.

Now that we know that we can get the difference between those two numbers: `a-b`
The last thing we need to do is to check if x is a divisor of our difference, by doing: (a-b) % x.
If x is not a divisor of (a-b) that means that we can’t fill out (a-b) with just x numbers. ex. (2, 2, 2)
Therefore we print NO.

Btw, we use %(modulo) to get the remainder of any number for ex: 10 % 5 = 0 and 10 % 4 = 2

First I hope you read the editorial - Editorial , now
Both A,B and X are positive. It does not matter which of the two (A,B) is smaller because

• if A < B you can perform the 1st operation i.e. A+X and B-X which will bring A and B closer by 2x
• if B < A you can perform the 2nd operation i.e. A-X and B+X which will still bring A and B closer by 2x
So you can conclude that in either of the operation you can only bring both of them closer by 2 * x and if the difference or the absolute difference between A and B is divisible by 2 * x only then it is possible for them to meet.
Example A = 10 , B = 2 and X = 2 (A - B = 8)now in 1 turn A = 8 , B = 4 (A - B = 4) and in 2nd turn A = 6 and B = 6 (A - B = 0). Observe that the distance between A and B is reduced by 2 * x (2 * 2 = 4) in each turn.
So the answer is if ( (A - B) % (2*x) == 0 ) ‘yes they will meet’ else ‘no they will not meet’.