CF1937A.Shuffle Party
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an. Initially, ai=i for each 1≤i≤n.
The operation swap(k) for an integer k≥2 is defined as follows:
- Let d be the largest divisor† of k which is not equal to k itself. Then swap the elements ad and ak.
Suppose you perform swap(i) for each i=2,3,…,n in this exact order. Find the position of 1 in the resulting array. In other words, find such j that aj=1 after performing these operations.
† An integer x is a divisor of y if there exists an integer z such that y=x⋅z.
给你一个数组 a1,a2,…,an。初始时,对每个 1≤i≤n,有 ai=i。
对整数 k≥2,定义操作 swap(k) 如下:
- 设 d 是 k 的最大真因子†(即 k 的最大因子,且不等于 k 本身)。然后交换数组元素 ad 和 ak。
假设你按顺序依次执行 swap(i),其中 i=2,3,…,n。求最终数组中元素 1 所在的位置。换言之,求满足 aj=1 的下标 j。
† 若存在整数 z 使得 y=x⋅z,则称整数 x 是 y 的一个因子。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains one integer n (1≤n≤109) — the length of the array a.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(1≤n≤109)——即数组 a 的长度。
输出格式
For each test case, output the position of 1 in the resulting array.
对于每个测试用例,输出结果数组中 1 的位置。
输入输出样例
输入#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 swap(2), a changes to [2,1,3,4] (the elements being swapped are underlined).
- After performing swap(3), a changes to [3,1,2,4].
- After performing swap(4), a changes to [3,4,2,1].
Finally, the element 1 lies on index 4 (that is, a4=1). Thus, the answer is 4.
在第一个测试用例中,数组为 [1],且未执行任何操作。
在第二个测试用例中,数组 a 的变化过程如下:
- 初始时,a 为 [1,2,3,4]。
- 执行 swap(2) 后,a 变为 [2,1,3,4](被交换的元素已加下划线)。
- 执行 swap(3) 后,a 变为 [3,1,2,4]。
- 执行 swap(4) 后,a 变为 [3,4,2,1]。
最终,元素 1 位于索引 4 处(即 a4=1)。因此,答案为 4。
输入解题思路,AI测评打分。不知道怎么写?