UVa 10161 Ant on a chessboard: simple math

Source: Internet
Author: User
Tags time limit

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.