#t1146. 点到原点的距离平方
点到原点的距离平方
Squared Distance to the Origin
Problem Description
The second lesson on structs: members take part in expressions.
Define a struct that represents a point in the plane:
struct Point {
int x;
int y;
};
Read the coordinates of points into structs, and for every point print the square of its distance to the origin . By the Pythagorean theorem the squared distance is simply — an integer, which neatly avoids the precision trouble of taking square roots.
Input Format
The first line contains a positive integer ; the next lines each contain two integers , the coordinates of one point.
Output Format
lines; line holds the squared distance from the -th point to the origin.
Sample Input
3
3 4
-1 0
0 0
Sample Output
25
1
0
Constraints
For 100% of the test data, and .
Hint: print the square of the distance — no square root is needed. The maximum of x * x + y * y is about , which fits comfortably in an int.