Spiral Pattern X91450


Statement
 

pdf   zip

html

On a square grid, we start in (0,0) and we draw a spiral path. Then, on this spiral path, we mark one square with the first color, then two squares with the second color, three squares with the third color, etc. To limit the number of colors, we pick a number k ∈ {2,3} (these values give the prettiest results) and use only k colors (we go back to color 1 instead of k+1). The results are shown on the pictures.

We would like to quickly calculate which color will be used on a square grid with given coordinates.

Input

Each line contains three integers k,x,y, where k ∈ {2,3} and |x|, |y| ≤ 1000000000.

Input ends with a line containing 0 0 0.

Output

For each k,x,y output the color of point (x,y), as a number from 1 to k. Positive x coordinates go rightwards, and positive y coordinates go upwards.

Public test cases
  • Input

    2 0 0
    2 -1 0
    2 -1 -1
    2 0 -1
    2 1 -1
    2 1 0
    2 1 1
    3 0 0
    3 -1 0
    3 -1 -1
    3 0 -1
    3 1 -1
    3 1 0
    3 1 1
    0 0 0
    

    Output

    1
    2
    2
    1
    1
    1
    2
    1
    2
    2
    3
    3
    3
    1
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++