CF1560C.Infinity Table
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
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.
Polycarp 发现了一张具有无穷多行和无穷多列的表格。行号从 1 开始编号,自最上方的行起;列号也从 1 开始编号,自最左侧的列起。
初始时,表格为空,而 Polycarp 想要将其填满。他按如下方式,将正整数从 1 开始依次填入表格中:

图中展示了数字 1 至 10 的填入位置,图中的箭头表示后续填数操作的方向。
表格最左上角(即第 1 行第 1 列)的格子首先填入数字 1。随后,他从 2 开始,按顺序将所有正整数填入表格,所遵循的规则如下:
首先,Polycarp 选取第 1 行中最左侧尚未填数的格子并填入下一个数。接着,在上一个已填格子的左邻格已被填数的前提下,他向下移动,并填入下一个格子。也就是说,他持续向下移动并填数,直到上一个已填格子的左邻格尚未被填数为止(参见上图中向下的竖直箭头)。
此后,他开始从右向左填数,直至到达第 1 列为止(参见上图中的水平箭头)。然后,Polycarp 再次选取第 1 行中最左侧尚未填数的格子,向下移动并继续该过程,如此反复。
Polycarp 的一位朋友有一个他最喜欢的数字 k。他想知道该数字位于表格的哪个格子中。请帮助他找出该数字所在格子的行号与列号,即满足该数字恰好位于第 r 行第 c 列交点处的 (r,c)。
输入格式
The first line contains one integer t (1≤t≤100) — the number of test cases. Then t test cases follow.
Each test case consists of one line containing one integer k (1≤k≤109) which location must be found.
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。接下来是 t 个测试用例。
每个测试用例由一行组成,该行包含一个整数 k(1≤k≤109),表示需要找到的位置。
输出格式
For each test case, output in a separate line two integers r and c (r,c≥1) separated by spaces — the indices of the row and the column containing the cell filled by the number k, respectively.
对于每个测试用例,在单独一行中输出两个整数 r 和 c(r,c≥1),以空格分隔——分别表示填入数字 k 的单元格所在的行索引和列索引。
输入输出样例
输入#1
7 11 14 5 4 1 2 1000000000
输出#1
2 4 4 3 1 3 2 1 1 1 1 2 31623 14130
输入解题思路,AI测评打分。不知道怎么写?