308702: CF1560C. Infinity Table

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Infinity Table

题意翻译

全体正整数按照如下方式排列在表格中: ![图片](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1560C/fbe22cdb57a9c1d91e54741c4b3ed27f17ef455a.png) Polycarp 会用以下方式把 $i$ 填充在表格中(设 $i-1$ 填在 $(x,y)$): - 若 $i=1$,把它填进左上角,再填 $i+1$。 - 否则,若 $x=1$,填在 $(x+1,y)$,再填 $i+1$。 - 否则,若 $y=1$,填在 $(1,x+1)$,再填 $i+1$。 - 否则,若 $x<y$,填在 $(x+1,y)$,再填 $i+1$。 - 否则,若 $x\ge y$,填在 $(x,y-1)$,再填 $i+1$。 求出第 $k$ 个数所在的位置 $(x,y)$。

题目描述

Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $ 1 $ , starting from the topmost one. The columns are numbered from $ 1 $ , starting from the leftmost one. Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $ 1 $ and so on to the table as follows. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1560C/fbe22cdb57a9c1d91e54741c4b3ed27f17ef455a.png)The figure shows the placement of the numbers from $ 1 $ to $ 10 $ . The following actions are denoted by the arrows.The leftmost topmost cell of the table is filled with the number $ 1 $ . Then he writes in the table all positive integers beginning from $ 2 $ sequentially using the following algorithm. First, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above). After that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on. A friend of Polycarp has a favorite number $ k $ . He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number $ k $ .

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. Then $ t $ test cases follow. Each test case consists of one line containing one integer $ k $ ( $ 1 \le k \le 10^9 $ ) which location must be found.

输出格式


For each test case, output in a separate line two integers $ r $ and $ c $ ( $ r, c \ge 1 $ ) separated by spaces — the indices of the row and the column containing the cell filled by the number $ k $ , respectively.

输入输出样例

输入样例 #1

7
11
14
5
4
1
2
1000000000

输出样例 #1

2 4
4 3
1 3
2 1
1 1
1 2
31623 14130

Input

题意翻译

全体正整数按照如下方式排列在表格中: ![图片](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1560C/fbe22cdb57a9c1d91e54741c4b3ed27f17ef455a.png) Polycarp 会用以下方式把 $i$ 填充在表格中(设 $i-1$ 填在 $(x,y)$): - 若 $i=1$,把它填进左上角,再填 $i+1$。 - 否则,若 $x=1$,填在 $(x+1,y)$,再填 $i+1$。 - 否则,若 $y=1$,填在 $(1,x+1)$,再填 $i+1$。 - 否则,若 $x<y$,填在 $(x+1,y)$,再填 $i+1$。 - 否则,若 $x\ge y$,填在 $(x,y-1)$,再填 $i+1$。 求出第 $k$ 个数所在的位置 $(x,y)$。

加入题单

上一题 下一题 算法标签: