题库练习 Weird LCM Operations
← 上一题 下一题 →

A11289 | Weird LCM Operations

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Given an integer $n$ , you construct an array $a$ of $n$ integers, where $a_i = i$ for all integers $i$ in the range $[1, n]$ . An operation on this array is defined as follows:

- Select three distinct indices $i$ , $j$ , and $k$ from the array, and let $x = a_i$ , $y = a_j$ , and $z = a_k$ .
- Update the array as follows: $a_i = \operatorname{lcm}(y, z)$ , $a_j = \operatorname{lcm}(x, z)$ , and $a_k = \operatorname{lcm}(x, y)$ , where $\operatorname{lcm}$ represents the least common multiple.

Your task is to provide a possible sequence of operations, containing at most $\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 $1$ , then all numbers from $1$ to $n$ should be present in this set.After all the operations $a_i \le 10^{18}$ should hold for all $1 \le i \le n$ .

We can show that an answer always exists.

输入格式

The first line contains one integer $t$ ( $1 \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 $n$ ( $3 \leq n \leq 3 \cdot 10^{4}$ ) — the length of the array.

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

输出格式

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

The next $k$ lines should contain the description of each operation i.e. $3$ integers $i$ , $j$ and $k$ , where $1 \leq i, j, k \leq n$ and all must be distinct.

输入输出样例

输入 #1
3
3
4
7
输出 #1
1
1 2 3
1
1 3 4
3
3 5 7
5 6 7
2 3 4
C++ 编辑器
输入
输出