CF1934E.Weird LCM Operations

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an integer nn, you construct an array aa of nn integers, where ai=ia_i = i for all integers ii in the range [1,n][1, n]. An operation on this array is defined as follows:

  • Select three distinct indices ii, jj, and kk from the array, and let x=aix = a_i, y=ajy = a_j, and z=akz = a_k.
  • Update the array as follows: ai=lcm⁡(y,z)a_i = \operatorname{lcm}(y, z), aj=lcm⁡(x,z)a_j = \operatorname{lcm}(x, z), and ak=lcm⁡(x,y)a_k = \operatorname{lcm}(x, y), where lcm⁡\operatorname{lcm} represents the least common multiple.

Your task is to provide a possible sequence of operations, containing at most ⌊n6⌋+5\lfloor \frac{n}{6} \rfloor + 5 operations such that after executing these operations, if you create a set containing the greatest common divisors (GCDs) of all subsequences with a size greater than 11, then all numbers from 11 to nn should be present in this set.

After all the operations ai≤1018a_i \le 10^{18} should hold for all 1≤i≤n1 \le i \le n.

We can show that an answer always exists.

给定一个整数 nn,你构造一个长度为 nn 的整数数组 aa,其中对所有 i∈[1,n]i \in [1, n] 均有 ai=ia_i = i。对该数组定义如下操作:

  • 从数组中选出三个互不相同的下标 ii、jj 和 kk,并令 x=aix = a_i、y=ajy = a_j、z=akz = a_k;
  • 按如下方式更新数组:ai=lcm⁡(y,z)a_i = \operatorname{lcm}(y, z),aj=lcm⁡(x,z)a_j = \operatorname{lcm}(x, z),ak=lcm⁡(x,y)a_k = \operatorname{lcm}(x, y),其中 lcm⁡\operatorname{lcm} 表示最小公倍数。

你的任务是给出一个可行的操作序列,该序列至多包含 ⌊n6⌋+5\lfloor \frac{n}{6} \rfloor + 5 次操作,使得执行完这些操作后,若构造一个集合,其元素为所有长度大于 11 的子序列的最大公约数(GCD),则该集合应包含 11 到 nn 中的所有整数。

此外,所有操作完成后,需满足对所有 1≤i≤n1 \le i \le n 均有 ai≤1018a_i \le 10^{18}。

我们可以证明这样的解总是存在的。

输入格式

The first line contains one integer tt (1≤t≤1021 \le t \le 10^2) — the number of test cases. The description of the test cases follows.

The first and only line of each test case contains an integer nn (3≤n≤3⋅1043 \leq n \leq 3 \cdot 10^{4}) — the length of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1043 \cdot 10^{4}.

第一行包含一个整数 tt(1≤t≤1021 \le t \le 10^2)——测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(3≤n≤3⋅1043 \leq n \leq 3 \cdot 10^{4})——数组的长度。

保证所有测试用例的 nn 之和不超过 3⋅1043 \cdot 10^{4}。

输出格式

The first line should contain an integer kk (0≤k≤⌊n6⌋+50 \leq k \leq \lfloor \frac{n}{6} \rfloor + 5) — where kk is the number of operations.

The next kk lines should contain the description of each operation i.e. 33 integers ii, jj and kk, where 1≤i,j,k≤n1 \leq i, j, k \leq n and all must be distinct.

第一行应包含一个整数 kk(0≤k≤⌊n6⌋+50 \leq k \leq \lfloor \frac{n}{6} \rfloor + 5),其中 kk 表示操作的次数。

接下来的 kk 行应描述每次操作,即每行包含三个整数 ii、jj 和 kk,满足 1≤i,j,k≤n1 \leq i, j, k \leq n,且三者互不相同。

输入输出样例

  • 输入#1

    3
    3
    4
    7

    输出#1

    1
    1 2 3
    1
    1 3 4
    3
    3 5 7
    5 6 7
    2 3 4

说明/提示

In the third test case, a=[1,2,3,4,5,6,7]a = [1, 2, 3, 4, 5, 6, 7].

First operation:

i=3i = 3, j=5j = 5, k=7k = 7

x=3x = 3, y=5y = 5, z=7z = 7.

a=[1,2,lcm⁡(y,z),4,lcm⁡(x,z),6,lcm⁡(x,y)]a = [1, 2, \operatorname{lcm}(y,z), 4, \operatorname{lcm}(x,z), 6, \operatorname{lcm}(x,y)] = [1,2,35,4,21,6,15][1, 2, \color{red}{35}, 4, \color{red}{21}, 6, \color{red}{15}].

Second operation:

i=5i = 5, j=6j = 6, k=7k = 7

x=21x = 21, y=6y = 6, z=15z = 15.

a=[1,2,35,4,lcm⁡(y,z),lcm⁡(x,z),lcm⁡(x,y)]a = [1, 2, 35, 4, \operatorname{lcm}(y,z), \operatorname{lcm}(x,z), \operatorname{lcm}(x,y)] = [1,2,35,4,30,105,42][1, 2, 35, 4, \color{red}{30}, \color{red}{105}, \color{red}{42}].

Third operation:

i=2i = 2, j=3j = 3, k=4k = 4

x=2x = 2, y=35y = 35, z=4z = 4.

a=[1,lcm⁡(y,z),lcm⁡(x,z),lcm⁡(x,y),30,105,42]a = [1, \operatorname{lcm}(y,z), \operatorname{lcm}(x,z), \operatorname{lcm}(x,y), 30, 105, 42] = [1,140,4,70,30,105,42][1, \color{red}{140}, \color{red}{4}, \color{red}{70}, 30, 105, 42].

Subsequences whose GCD equal to ii is as follows:

gcd⁡(a1,a2)=gcd⁡(1,140)=1\gcd(a_1, a_2) = \gcd(1, 140) = 1

gcd⁡(a3,a4)=gcd⁡(4,70)=2\gcd(a_3, a_4) = \gcd(4, 70) = 2

gcd⁡(a5,a6,a7)=gcd⁡(30,105,42)=3\gcd(a_5, a_6, a_7) = \gcd(30, 105, 42) = 3

gcd⁡(a2,a3)=gcd⁡(140,4)=4\gcd(a_2, a_3) = \gcd(140, 4) = 4

gcd⁡(a2,a4,a5,a6)=gcd⁡(140,70,30,105)=5\gcd(a_2, a_4, a_5, a_6) = \gcd(140, 70, 30, 105) = 5

gcd⁡(a5,a7)=gcd⁡(30,42)=6\gcd(a_5, a_7) = \gcd(30, 42) = 6

gcd⁡(a2,a4,a6,a7)=gcd⁡(140,70,105,42)=7\gcd(a_2, a_4, a_6, a_7) = \gcd(140, 70, 105, 42) = 7

在第三个测试用例中,a=[1,2,3,4,5,6,7]a = [1, 2, 3, 4, 5, 6, 7]。

第一次操作:

i=3i = 3, j=5j = 5, k=7k = 7

x=3x = 3, y=5y = 5, z=7z = 7。

a=[1,2,lcm⁡(y,z),4,lcm⁡(x,z),6,lcm⁡(x,y)]a = [1, 2, \operatorname{lcm}(y,z), 4, \operatorname{lcm}(x,z), 6, \operatorname{lcm}(x,y)] = [1,2,35,4,21,6,15][1, 2, \color{red}{35}, 4, \color{red}{21}, 6, \color{red}{15}]。

第二次操作:

i=5i = 5, j=6j = 6, k=7k = 7

x=21x = 21, y=6y = 6, z=15z = 15。

a=[1,2,35,4,lcm⁡(y,z),lcm⁡(x,z),lcm⁡(x,y)]a = [1, 2, 35, 4, \operatorname{lcm}(y,z), \operatorname{lcm}(x,z), \operatorname{lcm}(x,y)] = [1,2,35,4,30,105,42][1, 2, 35, 4, \color{red}{30}, \color{red}{105}, \color{red}{42}]。

第三次操作:

i=2i = 2, j=3j = 3, k=4k = 4

x=2x = 2, y=35y = 35, z=4z = 4。

a=[1,lcm⁡(y,z),lcm⁡(x,z),lcm⁡(x,y),30,105,42]a = [1, \operatorname{lcm}(y,z), \operatorname{lcm}(x,z), \operatorname{lcm}(x,y), 30, 105, 42] = [1,140,4,70,30,105,42][1, \color{red}{140}, \color{red}{4}, \color{red}{70}, 30, 105, 42]。

满足 gcd⁡\gcd 等于 ii 的子序列如下:

gcd⁡(a1,a2)=gcd⁡(1,140)=1\gcd(a_1, a_2) = \gcd(1, 140) = 1

gcd⁡(a3,a4)=gcd⁡(4,70)=2\gcd(a_3, a_4) = \gcd(4, 70) = 2

gcd⁡(a5,a6,a7)=gcd⁡(30,105,42)=3\gcd(a_5, a_6, a_7) = \gcd(30, 105, 42) = 3

gcd⁡(a2,a3)=gcd⁡(140,4)=4\gcd(a_2, a_3) = \gcd(140, 4) = 4

gcd⁡(a2,a4,a5,a6)=gcd⁡(140,70,30,105)=5\gcd(a_2, a_4, a_5, a_6) = \gcd(140, 70, 30, 105) = 5

gcd⁡(a5,a7)=gcd⁡(30,42)=6\gcd(a_5, a_7) = \gcd(30, 42) = 6

gcd⁡(a2,a4,a6,a7)=gcd⁡(140,70,105,42)=7\gcd(a_2, a_4, a_6, a_7) = \gcd(140, 70, 105, 42) = 7

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

首页