A11276 | Shuffle Party
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a_1, a_2, \ldots, a_n$ . Initially, $a_i=i$ for each $1 \le i \le n$ .
The operation $\texttt{swap}(k)$ for an integer $k \ge 2$ is defined as follows:
- Let $d$ be the largest divisor $^\dagger$ of $k$ which is not equal to $k$ itself. Then swap the elements $a_d$ and $a_k$ .
Suppose you perform $\texttt{swap}(i)$ for each $i=2,3,\ldots, n$ in this exact order. Find the position of $1$ in the resulting array. In other words, find such $j$ that $a_j = 1$ after performing these operations.
$^\dagger$ An integer $x$ is a divisor of $y$ if there exists an integer $z$ such that $y = x \cdot z$ .
The operation $\texttt{swap}(k)$ for an integer $k \ge 2$ is defined as follows:
- Let $d$ be the largest divisor $^\dagger$ of $k$ which is not equal to $k$ itself. Then swap the elements $a_d$ and $a_k$ .
Suppose you perform $\texttt{swap}(i)$ for each $i=2,3,\ldots, n$ in this exact order. Find the position of $1$ in the resulting array. In other words, find such $j$ that $a_j = 1$ after performing these operations.
$^\dagger$ An integer $x$ is a divisor of $y$ if there exists an integer $z$ such that $y = x \cdot z$ .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). The description of the test cases follows.
The only line of each test case contains one integer $n$ ( $1 \le n \le 10^9$ ) — the length of the array $a$ .
The only line of each test case contains one integer $n$ ( $1 \le n \le 10^9$ ) — the length of the array $a$ .
输出格式
For each test case, output the position of $1$ in the resulting array.
输入输出样例
输入 #1
4 1 4 5 120240229
输出 #1
1 4 4 67108864
In the first test case, the array is $[1]$ and there are no operations performed.
In the second test case, $a$ changes as follows:
- Initially, $a$ is $[1,2,3,4]$ .
- After performing $\texttt{swap}(2)$ , $a$ changes to $[\underline{2},\underline{1},3,4]$ (the elements being swapped are underlined).
- After performing $\texttt{swap}(3)$ , $a$ changes to $[\underline{3},1,\underline{2},4]$ .
- After performing $\texttt{swap}(4)$ , $a$ changes to $[3,\underline{4},2,\underline{1}]$ .
Finally, the element $1$ lies on index $4$ (that is, $a_4 = 1$ ). Thus, the answer is $4$ .
In the second test case, $a$ changes as follows:
- Initially, $a$ is $[1,2,3,4]$ .
- After performing $\texttt{swap}(2)$ , $a$ changes to $[\underline{2},\underline{1},3,4]$ (the elements being swapped are underlined).
- After performing $\texttt{swap}(3)$ , $a$ changes to $[\underline{3},1,\underline{2},4]$ .
- After performing $\texttt{swap}(4)$ , $a$ changes to $[3,\underline{4},2,\underline{1}]$ .
Finally, the element $1$ lies on index $4$ (that is, $a_4 = 1$ ). Thus, the answer is $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted