CF2158F1.Distinct GCDs (Easy Version)

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, n≤700n \leq 700. You can hack only if you solved all versions of this problem.

Legend has it that when Gauss was a young schoolboy, his teacher tasked the class with summing the integers from 11 to 100100, likely as a way to keep them occupied for a while. However, young Gauss quickly came up with the formula sum=n(n+1)2\text{sum} = \frac{n(n+1)}{2} and found the answer in mere moments. Centuries later, Gauss appears before you in a nightmare with a daunting task...

You are given a positive integer nn, find a sequence of integers [a1,a2,…,an][a_1, a_2, \ldots, a_n] such that 1≤ai≤10181 \leq a_i \leq 10^{18} for all 1≤i≤n1 \leq i \leq n, and the GCDs of pairwise adjacent elements of aa are all distinct. Formally,

gcd⁡(ai,ai+1)≠gcd⁡(aj,aj+1)\gcd(a_i, a_{i+1}) \neq \gcd(a_j, a_{j+1}) for each 1≤i<j<n1 \leq i \lt j \lt n

Additionally, aa should have the minimum possible number of distinct elements.

这是该问题的简单版本。两个版本的区别在于,在此版本中,n≤700n \leq 700。仅当您解决了该问题的所有版本后,才可进行 hack。

传说高斯还是个小学生时,他的老师曾让全班同学计算从 11 到 100100 的所有整数之和,很可能是为了让他们暂时安静一会儿。然而,年少的高斯迅速推导出了公式 sum=n(n+1)2\text{sum} = \frac{n(n+1)}{2},并在片刻之间就得出了答案。几个世纪之后,高斯却在你的噩梦中现身,并交给你一项艰巨的任务……

给定一个正整数 nn,请构造一个整数序列 [a1,a2,…,an][a_1, a_2, \ldots, a_n],使得对所有 1≤i≤n1 \leq i \leq n 均满足 1≤ai≤10181 \leq a_i \leq 10^{18},且序列 aa 中所有相邻元素对的最大公约数互不相同。形式化地,

对任意 1≤i<j<n1 \leq i \lt j \lt n,均有 gcd⁡(ai,ai+1)≠gcd⁡(aj,aj+1)\gcd(a_i, a_{i+1}) \neq \gcd(a_j, a_{j+1})。

此外,序列 aa 中不同元素的个数应尽可能少。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2001 \le t \le 200). The description of the test cases follows.

The first and only line of each test case contains a single integer nn (2≤n≤7002 \leq n \leq 700) — the size of the sequence to be found.

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

每个测试用例仅有一行,包含一个整数 nn(2≤n≤7002 \leq n \leq 700)——即待求序列的长度。

输出格式

For each test case, output nn space-separated positive integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤10181 \leq a_i \leq 10^{18}) on a new line that satisfy the condition in the statement. If there are multiple solutions, print any of them.

It can be proven that under the problem constraints, a solution always exists.

对于每个测试用例,在一行内输出 nn 个以空格分隔的正整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤10181 \leq a_i \leq 10^{18}),使其满足题目陈述中的条件。若存在多个解,输出任意一个即可。

可以证明,在本题的约束条件下,解总是存在的。

输入输出样例

  • 输入#1

    3
    2
    5
    7

    输出#1

    2 2
    1 4 4 6 6
    4 4 6 6 9 9 4

说明/提示

For the second test case, the GCDs of adjacent elements are [gcd⁡(1,4),gcd⁡(4,4),gcd⁡(4,6),gcd⁡(6,6)]=[1,4,2,6][\gcd(1, 4), \gcd(4, 4), \gcd(4, 6), \gcd(6, 6)] = [1, 4, 2, 6], all of which are distinct.

For the third test case, the GCDs of adjacent elements are [gcd⁡(4,4),gcd⁡(4,6),gcd⁡(6,6),gcd⁡(6,9),gcd⁡(9,9),gcd⁡(9,4)]=[4,2,6,3,9,1][\gcd(4, 4), \gcd(4, 6), \gcd(6, 6), \gcd(6, 9), \gcd(9, 9), \gcd(9, 4)] = [4, 2, 6, 3, 9, 1], all of which are distinct.

For each test case, it can be proven that no sequence with fewer distinct elements exists such that all adjacent GCDs are distinct.

对于第二个测试用例,相邻元素的最大公约数(GCD)序列为 [gcd⁡(1,4),gcd⁡(4,4),gcd⁡(4,6),gcd⁡(6,6)]=[1,4,2,6][\gcd(1, 4), \gcd(4, 4), \gcd(4, 6), \gcd(6, 6)] = [1, 4, 2, 6],其中所有值互不相同。

对于第三个测试用例,相邻元素的最大公约数(GCD)序列为 [gcd⁡(4,4),gcd⁡(4,6),gcd⁡(6,6),gcd⁡(6,9),gcd⁡(9,9),gcd⁡(9,4)]=[4,2,6,3,9,1][\gcd(4, 4), \gcd(4, 6), \gcd(6, 6), \gcd(6, 9), \gcd(9, 9), \gcd(9, 4)] = [4, 2, 6, 3, 9, 1],其中所有值互不相同。

对于每个测试用例,均可证明:不存在元素种类数更少的序列,使得所有相邻元素的最大公约数互不相同。

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

首页