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 ai,bi 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 ans1i,ans2i, the number of type A creatures, and the number of type B creatures. Consider that ans1i+ans2i should be smallest possible.

Constraints

1t100 000

1ai,bi109

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

?