Equal Integers solution codechef

Equal Integers solution codechef

Chef has two integers XX and YY. Chef wants to perform some operations to make XX and YY equal. In one operation, Chef can either:

  • set X:=X+1X:=X+1
  • or set Y:=Y+2Y:=Y+2

Find the minimum number of operations required to make XX and YY equal.

Input Format

  • The first line contains a single integer TT — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two space separated integers XX and YY.

Output Format

Equal Integers solution codechef

For each test case, print the minimum number of operations required to make XX and YY equal.

Constraints

  • 1T1041≤T≤104
  • 1X,Y1091≤X,Y≤109

Sample Input 1 

5
3 4
5 5
7 3
5 2
7 12

Sample Output 1 

1
0
2
3
5

Equal Integers solution codechef 

Explanation

Let (x,y)(x,y) denote the values of XX and YY respectively.

Test case 11: Only one operation is required: (3,4)−→−−−−X:=X+1(4,4)(3,4)→X:=X+1(4,4)

Test case 22: No operations are required since XX and YY are already equal.

Test case 33: Two operations are required: (7,3)−→−−−−Y:=Y+2(7,5)−→−−−−Y:=Y+2(7,7)(7,3)→Y:=Y+2(7,5)→Y:=Y+2(7,7)

Test case 44: Three operations are required. One such sequence of operations is: (5,2)−→−−−−Y:=Y+2(5,4)−→−−−−X:=X+1(6,4)−→−−−−Y:=Y+2(6,6)

SOLUTION

Click Here

Leave a Comment

Your email address will not be published.