Algorithm


A. Exciting Bets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Welcome to Rockport City!

It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b)���(�,�), where gcd(x,y)���(�,�) denotes the greatest common divisor (GCD) of integers x and y. To make the race more exciting, you can perform two types of operations:

  1. Increase both a and b by 11.
  2. Decrease both a and b by 11. This operation can only be performed if both a and b are greater than 00.

In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.

Note that gcd(x,0)=x���(�,0)=� for any x0�≥0.

Input

The first line of input contains a single integer t (1t51031≤�≤5⋅103) — the number of test cases.

The first and the only line of each test case contains two integers a and b (0a,b10180≤�,�≤1018).

Output

For each test case, print a single line containing two integers.

If the fans can get infinite excitement, print 0 0.

Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.

Example
input
Copy
4
8 5
1 2
4 4
3 9
output
Copy
3 1
1 0
0 0
6 3
Note

For the first test case, you can apply the first operation 11 time to get a=9�=9 and b=6�=6. It can be shown that 33 is the maximum excitement possible.

For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 11. Since the initial excitement is also 11, you don't need to apply any operation.

For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.

For the fourth test case, you can apply the second operation 33 times to get a=0�=0 and b=6�=6. Since, gcd(0,6)=6���(0,6)=6, the fans will get an excitement of 66.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    ll a, b;
    cin>>a>>b;
    ll diff = (a >= b) ? (a - b) : (b - a);
    if(a > b){
      cout<<diff<<" "<<min(diff - (a % diff), b % diff)<<endl;
    }
    else if(b > a){
      cout<<diff<<" "<<min(diff - (b % diff), a % diff)<<endl;
    }
    else{
      cout<<0<<" "<<0<<endl;
    }
  }


}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
8 5
1 2
4 4
3 9

Output

x
+
cmd
3 1
1 0
0 0
a5 6 3
Advertisements

Demonstration


Codeforcess Solution 1543-A A. Exciting Bets ,C++, Java, Js and Python ,1543-A,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+