Zoo creatures

3.5

20 votes
Basic Programming, , Basic Math, Algorithms, Number theory
Problem

A zoo have two types of creatures, type A has \(a\) hands and type B has \(b\) hands. Spawn the smallest number of creatures so they can grab each other hands in the following conditions:

  • Each creature should only grab the hands of another creature type.
  • Each creature should grab with all of its hands.

What is the smallest number of creature needed?

Note: It is guaranteed that under the given conditions answer is unique.

Input  format

  • The first line contains \(t\) number of test cases .
  • Each of the next \(t\) lines contains two integers \(a_i, b_i\) denoting the number of type A creature hands and the number of type B creature hands.

Output format

The output contains \(t\) lines. For each test case, print two numbers \(ans1_i, ans2_i\), the number of type A creatures, and the number of type B creatures. Consider that \(ans1_i + ans2_i\) should be smallest possible.

Constraints

\(1 \leq t \leq 100 \space 000\)

\(1 \leq a_i, b_i \leq 10^9\)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

At least 1 of each creture types needed.

One creature of type A has 20 hands.

Ten creatures of  type B have 20 hands.

So they can grab each other hands in asked conditions.

Editor Image

?