F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Square Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 895    Accepted Submission(s): 286


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, $a$, into another, $b$, where $a \neq b$. In a single operation, Rikka can either add a positive square number to $a$, or subtract a positive square number from $a$. The goal is to convert $a$ into $b$ by executing the least number of operations.

A square number is an integer that is the product of some integer with itself. For example, $1$, $4$, $9$, and $16$ are square numbers, as they are the squares of $1$, $2$, $3$, and $4$, respectively.

The problem might seem complex for Rikka. Can you assist Rikka in solving this?
 

Input
The first line contains one integer $T$ ($1\le T\le 10^3$), indicating the number of test cases.

For each test case, the only line contains two integers $a,b$ ($1\le a,b\le 10^9$, $a\neq b$).
 

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 $2^2=4$ to $a$, and then subtract $1^2=1$ from $a$. After executing two operations, $a$ becomes $4$.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:45:26, Gzip enabled