Integer Moves (Codeforces 1657A)
Tags: Math, brute force

There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases.The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.

Output: For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.

Note: In the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ 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: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.

Sample Inputs:
3
8 6
0 0
9 15

Sample Outputs:
1
0
2

Solution (Python):
for inh in range(int(input())):
    (x, y) = map(int, input().split())
    f = (x ** 2 + y ** 2) ** 0.5
    d = int(f)
    if f == 0:
        print(0)
    elif d == f:
        print(1)
    else:
        print(2)

Solution (Python):
for s in [*open(0)][1:]:
    (x, y) = map(int, s.split())
    print((x | y > 0) + (int((d := ((x * x + y * y) ** 0.5))) < d))

Solution (Python):
import math
import sys
input = sys.stdin.readline

def inp():
    return int(input())

def inlt():
    return list(map(int, input().split()))

def insr():
    s = input()
    return list(s[:len(s) - 1])

def invr():
    return map(int, input().split())
t = inp()
for i in range(t):
    (x, y) = invr()
    temp = math.sqrt(y ** 2 + x ** 2)
    if int(temp) == 0:
        print(0)
        continue
    elif temp == int(temp):
        print(1)
        continue
    print(2)