Ant on a Chessboard

2020年1月17日 1154点热度 0人点赞 0条评论

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.

















25
24 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

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论