Spiral
InterviewTime limit1sMemory limit512 MB
Place B beans in a clockwise inward spiral on an N by N board and report the row and column of the B-th bean.
- Level
Medium6 of 10
- Topics
- Math, Implementation, Binary search, Simulation
- Solved
- No attempts yet
Problem
You place beans on an board, one bean per square, in the spiral order shown in the figure.
Start at the top left square and move right. When the next square is off the board or already holds a bean, turn down. The same rule turns down into left, left into up, and up back into right, so the direction cycles right, down, left, up until all beans are placed.
Given and , find the coordinates of the square that holds the last bean. A coordinate means row counted from the top and column counted from the left. The figure shows and , where the last bean lands on .

Input
One line with two integers and separated by a space, where and .
Output
Print the row number and the column number of the last bean on one line, separated by a space.