A. Integer Moves
There's a chip in the point of the coordinate plane. In one operation, you can move the chip from some point to some point if the Euclidean distance between these two points is an integer (i.e. is integer).
Your task is to determine the minimum number of operations required to move the chip from the point to the point .
The first line contains a single integer () — number of test cases.
The single line of each test case contains two integers and () — the coordinates of the destination point.
For each test case, print one integer — the minimum number of operations required to move the chip from the point to the point .
3
8 6
0 0
9 15
1
0
2
In the first example, one operation is enough. is an integer.
In the second example, the chip is already at the destination point.
In the third example, the chip can be moved as follows: . and are integers.
solution
#include<iostream>
#include<cmath>
using namespace std;
void solve()
{
int x, y;
double ans;
cin >> x >> y;
ans = sqrt(pow(0 - x, 2) + pow(0 - y, 2));
if (x == 0 && y == 0)
cout << 0 << "\n";
else if (ans == (int)ans)
cout << 1 << "\n";
else
cout << 2 << "\n";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
No comments:
Post a Comment