Codeforces Round 931 (Div. 2)
E
Weird LCM Operations
Codeforces
3000
原题
← D2→
翻译中…

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.

翻译中…

Input

翻译中…

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}$.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

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

翻译中…

First operation:

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Second operation:

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Third operation:

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Subsequences whose GCD equal to $i$ is as follows:

翻译中…

$\gcd(a_1, a_2) = \gcd(1, 140) = 1$

翻译中…

$\gcd(a_3, a_4) = \gcd(4, 70) = 2$

翻译中…

$\gcd(a_5, a_6, a_7) = \gcd(30, 105, 42) = 3$

翻译中…

$\gcd(a_2, a_3) = \gcd(140, 4) = 4$

翻译中…

$\gcd(a_2, a_4, a_5, a_6) = \gcd(140, 70, 30, 105) = 5$

翻译中…

$\gcd(a_5, a_7) = \gcd(30, 42) = 6$

翻译中…

$\gcd(a_2, a_4, a_6, a_7) = \gcd(140, 70, 105, 42) = 7$

翻译中…

样例

Input #1
3
3
4
7
Output #1
1
1 2 3
1
1 3 4
3
3 5 7
5 6 7
2 3 4
InputCopy OutputCopy
题目信息
题号
1934E
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。