Spiral Coordinates
InterviewTime limit1sMemory limit128 MB
Find the (row, column) of N in the clockwise integer spiral centered at 1.
- Level
Medium4 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
Lay out the positive integers as shown below. The number 1 sits at the centre and the rest wind outwards clockwise in an infinite spiral.
21 22 23 24 25 26
20 7 8 9 10 ...
19 6 1 2 11 ...
18 5 4 3 12 ...
17 16 15 14 13 ...
Let the centre, the number 1, have position . Row numbers grow from top to bottom and column numbers grow from left to right, so the number 3 is at .
Given an integer , find the position of the cell that holds it. The answer is a string of the form (R,C), where is the row and is the column. Neither nor may carry a leading zero.
Input
The first line contains the number of test cases . Each of the next lines contains one integer ().
Output
For each test case, print the position of on its own line in the form (R,C). Put no spaces inside the parentheses, and prefix a negative coordinate with -.