Small Numbers
Time limit2sMemory limit512 MB
Given positive integers a and b, reduce their sum using common-divisor divisions and factor moves between them. Report the minimum sum and one minimizing pair.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Little Vlad has two favorite numbers and . Recently at school he learned division and multiplication, and he immediately started dividing and multiplying his favorite numbers.
He wrote and in his notebook and came up with three cool operations he wants to perform on his numbers:
- Divide both numbers by one of their common divisors.
- Divide by one of its divisors , multiply by .
- Divide by one of its divisors , multiply by .
After performing an operation he erases his old numbers and replaces them with the new ones. He may continue performing operations or stop.
Since Vlad is small, he wants the numbers to be smaller. So he tries to minimize the sum of and , but cannot manage it on his own. Help him determine the minimum sum he can obtain with these operations, and give an example of a final and with that sum.
Input
Input data contains multiple test cases. The first line contains integer , the number of test cases ().
Each test case is described by a single line containing integers and (), Vlad's favorite numbers.
Output
For each test case output one line: a pair with the minimum sum that can be obtained by performing operations from the list.