#P9886. Rikka with Square Numbers
Rikka with Square Numbers
Rikka with Square Numbers
Problem Description
Rikka struggles with math. Observing this, Yuta decides to help her improve by assigning some math practice tasks. Here is one such task. The task requires transforming one integer, , into another, , where . In a single operation, Rikka can either add a positive square number to , or subtract a positive square number from . The goal is to convert into by executing the least number of operations. A square number is an integer that is the product of some integer with itself. For example, , , , and are square numbers, as they are the squares of , , , and , respectively. The problem might seem complex for Rikka. Can you assist Rikka in solving this?
Input
The first line contains one integer (), indicating the number of test cases. For each test case, the only line contains two integers (, ).
Output
For each test case, output a single line containing one integer, indicating the minimum number of operations required.
Sample Input
2
1 4
5 1
Sample Output
2
1
Hint
Consider the first sample where Rikka can add to , and then subtract from . After executing two operations, becomes .
Source
2023“钉耙编程”中国大学生算法设计超级联赛(8)