欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1560C.Infinity Table
Infinity Table
Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from , starting from the topmost one. The columns are numbered from , starting from the leftmost one.
Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from and so on to the table as follows.
The figure shows the placement of the numbers from to . The following actions are denoted by the arrows.
The leftmost topmost cell of the table is filled with the number . Then he writes in the table all positive integers beginning from 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 . 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 .
Input
The first line contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of one line containing one integer () which location must be found.
Output
For each test case, output in a separate line two integers and () separated by spaces — the indices of the row and the column containing the cell filled by the number , respectively.
Samples
7
11
14
5
4
1
2
1000000000
2 4
4 3
1 3
2 1
1 1
1 2
31623 14130
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |