Ant on a Chessboard
时间: 1ms 内存:64M
描述:
One day, an ant named Alice came upon an M x M chessboard. She wanted to explore all the cells of the board. So she began to walk along the board by peeling off a corner of the board.
Alice started at square (1, 1). First, she went up for a step, then a step to the right, and a step downward. After that, she went a step to the right, then two steps upward, and then two grids to the left. In each round, she added one new row and one new column to the corner she had explored.
For example, her first 25 steps went like this, where the numbers in each square denote on which step she visited it.
2524 23 22 21
10 11 12 13 20
9 8 7 14 19
2 3 6 15 18
1 4 5 16 17
Her 8th step put her on square (2, 3), while her 20th step put her on square (5, 4). Your task is to decide where she was at a given time, assuming the chessboard is large enough to accept all movements.
输入:
The input file will contain several lines, each with an integer N denoting the step number where 1<=N<=2x 109. The file will terminate with a line that contains the number 0.
输出:
For each input situation, print a line with two numbers (x,y) denoting the column and the row number, respectively. There must be a single space between them.
示例输入:
8
20
25
0
示例输出:
2 3
5 4
1 5
提示:
参考答案:
文章评论