# CHFTIRED - EDITORIAL

Setter: Misha Chorniy
Tester: Zhong Ziqian
Editorialist: Taranpreet Singh

Cakewalk

None.

### PROBLEM:

Given Two numbers A and B, Determine whether we make both numbers equal by the following operation any number of times.

• Choose any value d.
• Perform exactly one of following
• Add d-1 to A and d to B.
• Add d to A and d-1 to B.

### SUPER QUICK EXPLANATION

• Value of d is useless. The first operation can be seen as Subtracting 1 from A while the Second operation is subtracting 1 from B.
• Since we need A-B = 0, we can easily decrease the larger of given numbers by applying above operation.
• Print â€śYESâ€ť is the solution.

### EXPLANATION

The thing is, that we need to notice the effect of each operation on A-B. For A == B, we need A-B = 0. Now let us see how operations affect the value A-B.

If we choose to add d-1 to A and d to B, the value of A-B becomes (A+d-1)-(B+d) = A-B-1 which is same as subtracting 1 from A-B.

If we choose to add d to A and d to B, the value of A-B becomes (A+d)-(B+d-1) = A-B+1 which is same as adding 1 to A-B.

Now, Since we want to achieve A-B = 0, we can see that if A-B > 0 we can apply the first operation repetitively to achieve A == B. Otherwise, if A-B < 0, we can apply operation of the second type any number of times to achieve A == B.

Thatâ€™s all for this problem.

Want the solution, Just print YES for every case.

Challenge problem
Given Two numbers A and B and a number x, Determine whether we make achieve A == B by the following operation any number of times.

• Choose any value d.
• Perform exactly one of following
• Add d-x to A and d to B.
• Add d to A and d-x to B.

### Time Complexity

Time complexity is O(T) since we only use print statement for every test case.

### AUTHORâ€™S AND TESTERâ€™S SOLUTIONS:

Feel free to Share your approach, If it differs. Suggestions are always welcomed.

2 Likes

Simply take d = 1 every time !

Plz, post the solution of Challenge problem given in this Editorial.

1 Like

Answer is yes if |A - B| is divisible by x. Otherwise no.

1 Like