Skip to main content
Back to problems
Codeforces
Easy
Math
Geometry
Point on Spiral

Determine the coordinates of a point on an outward square spiral after moving a given number of steps from the origin.

Acceptance 0%
Problem Statement

Given an integer position nn on an infinite square spiral that starts at the origin and expands outward, find the coordinates of the nn-th point visited by the spiral.

The spiral begins at (0,0)(0, 0) 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 nn positions in this spiral.

Input Format

  • A single integer nn.

Output Format

  • Print two integers: the xx and yy coordinates of the nn-th point on the spiral.

Constraints

  • 1n1091 \le n \le 10^9
  • Coordinates fit in 32-bit signed integers.
Examples
Sample cases returned by the problem API.

Example 1

Input

1

Output

0 0

Explanation

The spiral starts at the origin, so the first point is (0,0)(0, 0).

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.