Determine the coordinates of a point on an outward square spiral after moving a given number of steps from the origin.
Given an integer position on an infinite square spiral that starts at the origin and expands outward, find the coordinates of the -th point visited by the spiral.
The spiral begins at and continues by moving in a fixed turning order while increasing the covered square layer by layer. Your task is to output the coordinates of the point reached after exactly positions in this spiral.
Input Format
- A single integer .
Output Format
- Print two integers: the and coordinates of the -th point on the spiral.
Constraints
- Coordinates fit in 32-bit signed integers.
Example 1
Input
1
Output
0 0
Explanation
The spiral starts at the origin, so the first point is .
Example 2
Input
2
Output
1 0
Explanation
The second point is one step to the right from the origin in the spiral traversal.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.