A15780 | Last Number
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a multiset $S$ . Initially, $S = \{1,2,3, \ldots, n\}$ .
You will perform the following operation $n-1$ times.
- Choose the largest number $S_{\text{max}}$ in $S$ and the smallest number $S_{\text{min}}$ in $S$ . Remove the two numbers from $S$ , and add $S_{\text{max}} - S_{\text{min}}$ into $S$ .
It's easy to show that there will be exactly one number left after $n-1$ operations. Output that number.
You will perform the following operation $n-1$ times.
- Choose the largest number $S_{\text{max}}$ in $S$ and the smallest number $S_{\text{min}}$ in $S$ . Remove the two numbers from $S$ , and add $S_{\text{max}} - S_{\text{min}}$ into $S$ .
It's easy to show that there will be exactly one number left after $n-1$ operations. Output that number.
输入格式
Each test contains multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 10^5$ ) — the number of test cases. Their description follows.
For each test case, one single line contains a single integer $n$ ( $2 \le n \le 10^9$ ) — the initial size of the multiset $S$ .
For each test case, one single line contains a single integer $n$ ( $2 \le n \le 10^9$ ) — the initial size of the multiset $S$ .
输出格式
For each test case, output an integer denoting the only number left after $n-1$ operations.
输入输出样例
输入 #1
5 2 4 7 15 177567
输出 #1
1 2 2 4 33914
We show how the multiset $S$ changes for $n=4$ .
- Operation $1$ : $S=\{1,2,3,4\}$ , remove $4$ , $1$ , add $3$ .
- Operation $2$ : $S=\{2,3,3\}$ , remove $3$ , $2$ , add $1$ .
- Operation $3$ : $S=\{1,3\}$ , remove $3$ , $1$ , add $2$ .
- Final: $S = \{2\}$ .
Thus, the answer for $n = 4$ is $2$ .
- Operation $1$ : $S=\{1,2,3,4\}$ , remove $4$ , $1$ , add $3$ .
- Operation $2$ : $S=\{2,3,3\}$ , remove $3$ , $2$ , add $1$ .
- Operation $3$ : $S=\{1,3\}$ , remove $3$ , $1$ , add $2$ .
- Final: $S = \{2\}$ .
Thus, the answer for $n = 4$ is $2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted