CF1059C.Sequence Transformation
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's call the following process a transformation of a sequence of length n.
If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of n integers: the greatest common divisors of all the elements in the sequence before each deletion.
You are given an integer sequence 1,2,…,n. Find the lexicographically maximum result of its transformation.
A sequence a1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bn, if there is an index i such that aj=bj for all j<i, and ai>bi.
我们称以下过程为一个长度为 n 的序列的变换:
- 若序列为空,则过程结束;
- 否则,将该序列中所有元素的最大公约数(GCD)添加到结果中,并从序列中任意移除一个元素。
因此,当过程结束时,我们将得到一个由 n 个整数组成的序列:即每次删除前,原序列所有元素的 GCD。
现给定整数序列 1,2,…,n。请找出其变换所能得到的字典序最大的结果。
序列 a1,a2,…,an 字典序大于序列 b1,b2,…,bn,当且仅当存在某个下标 i,使得对所有 j<i 都有 aj=bj,且 ai>bi。
输入格式
The first and only line of input contains one integer n (1≤n≤106).
输入仅有一行,包含一个整数 n(1≤n≤106)。
输出格式
Output n integers — the lexicographically maximum result of the transformation.
输出 n 个整数——变换后字典序最大的结果。
输入输出样例
输入#1
3
输出#1
1 1 3
输入#2
2
输出#2
1 2
输入#3
1
输出#3
1
说明/提示
In the first sample the answer may be achieved this way:
- Append GCD(1,2,3)=1, remove 2.
- Append GCD(1,3)=1, remove 1.
- Append GCD(3)=3, remove 3.
We get the sequence [1,1,3] as the result.
在第一个样例中,答案可以通过以下方式得到:
- 添加 GCD(1,2,3)=1,然后移除 2。
- 添加 GCD(1,3)=1,然后移除 1。
- 添加 GCD(3)=3,然后移除 3。
最终得到的结果序列为 [1,1,3]。
输入解题思路,AI测评打分。不知道怎么写?