10161-ant on a chessboard
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem &problem=1102
Background
One day, a ant called Alice came to a m*m chessboard. She wanted to go around all the grids. So she began to walk along the chessboard according to this way: (can assume that her speed be one grid per second)
At the the second, Alice is standing at (1,1). Firstly she went up for a grid, then a grid to the right, a grid downward. After this, she went a grid to the right, then two grids upward, and then two grids to the left...in a word, the path is Li Ke a snake.
For example, her the seconds went like this:
(The numbers in the grids stands for the "time" she went into the grids)
At the 8th second, she is in (2,3), and at 20th second, she is at (5,4).
Your task is to decide where she was in a given time.
(You can assume this M is large enough)
Input
Input file would contain several lines, and each line contains a number N (1<=N<=2*10^9), which stands to the time. The file is ended with a line, that contains a number 0.
Output
For each input situation your should print a line with two numbers (x, y), the column and the row number, there must to be onl Y a space between them.
Sample Input
8
20
25
0
Sample Output
2 3
5 4
1 5
The row and column corresponding to the number are found.
Thinking: Find the law, odd lines, starting with the square of the number of rows. Even series, starting with the square of the number of columns. Rows and columns have a pattern that matches numbers. Locate the row and column in turn.