CF1937A.Shuffle Party

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n. Initially, ai=ia_i=i for each 1≤i≤n1 \le i \le n.

The operation swap(k)\texttt{swap}(k) for an integer k≥2k \ge 2 is defined as follows:

  • Let dd be the largest divisor†^\dagger of kk which is not equal to kk itself. Then swap the elements ada_d and aka_k.

Suppose you perform swap(i)\texttt{swap}(i) for each i=2,3,…,ni=2,3,\ldots, n in this exact order. Find the position of 11 in the resulting array. In other words, find such jj that aj=1a_j = 1 after performing these operations.

†^\dagger An integer xx is a divisor of yy if there exists an integer zz such that y=x⋅zy = x \cdot z.

给你一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n。初始时,对每个 1≤i≤n1 \le i \le n,有 ai=ia_i = i。

对整数 k≥2k \ge 2,定义操作 swap(k)\texttt{swap}(k) 如下:

  • 设 dd 是 kk 的最大真因子†^\dagger(即 kk 的最大因子,且不等于 kk 本身)。然后交换数组元素 ada_d 和 aka_k。

假设你按顺序依次执行 swap(i)\texttt{swap}(i),其中 i=2,3,…,ni = 2, 3, \ldots, n。求最终数组中元素 11 所在的位置。换言之,求满足 aj=1a_j = 1 的下标 jj。

†^\dagger 若存在整数 zz 使得 y=x⋅zy = x \cdot z,则称整数 xx 是 yy 的一个因子。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains one integer nn (1≤n≤1091 \le n \le 10^9) — the length of the array aa.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤1091 \le n \le 10^9)——即数组 aa 的长度。

输出格式

For each test case, output the position of 11 in the resulting array.

对于每个测试用例,输出结果数组中 11 的位置。

输入输出样例

  • 输入#1

    4
    1
    4
    5
    120240229

    输出#1

    1
    4
    4
    67108864

说明/提示

In the first test case, the array is [1][1] and there are no operations performed.

In the second test case, aa changes as follows:

  • Initially, aa is [1,2,3,4][1,2,3,4].
  • After performing swap(2)\texttt{swap}(2), aa changes to [2‾,1‾,3,4][\underline{2},\underline{1},3,4] (the elements being swapped are underlined).
  • After performing swap(3)\texttt{swap}(3), aa changes to [3‾,1,2‾,4][\underline{3},1,\underline{2},4].
  • After performing swap(4)\texttt{swap}(4), aa changes to [3,4‾,2,1‾][3,\underline{4},2,\underline{1}].

Finally, the element 11 lies on index 44 (that is, a4=1a_4 = 1). Thus, the answer is 44.

在第一个测试用例中,数组为 [1][1],且未执行任何操作。

在第二个测试用例中,数组 aa 的变化过程如下:

  • 初始时,aa 为 [1,2,3,4][1,2,3,4]。
  • 执行 swap(2)\texttt{swap}(2) 后,aa 变为 [2‾,1‾,3,4][\underline{2},\underline{1},3,4](被交换的元素已加下划线)。
  • 执行 swap(3)\texttt{swap}(3) 后,aa 变为 [3‾,1,2‾,4][\underline{3},1,\underline{2},4]。
  • 执行 swap(4)\texttt{swap}(4) 后,aa 变为 [3,4‾,2,1‾][3,\underline{4},2,\underline{1}]。

最终,元素 11 位于索引 44 处(即 a4=1a_4 = 1)。因此,答案为 44。

输入解题思路,AI测评打分。不知道怎么写?

首页