Description

Let's call the following process a transformation of a sequence of length nn .

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 nn integers: the greatest common divisors of all the elements in the sequence before each deletion.

You are given an integer sequence 1,2,…,n1,2,…,n . Find the lexicographically maximum result of its transformation.

A sequence a1,a2,…,ana1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bnb1,b2,…,bn , if there is an index ii such that aj=bjaj=bj for all j<ij<i , and ai>biai>bi .

Input

The first and only line of input contains one integer nn (1≤n≤1061≤n≤106 ).

Output

Output nn integers  — the lexicographically maximum result of the transformation.

Sample Input

 

Input
3
Output
1 1 3 
Input
2
Output
1 2 
Input
1
Output
1 

Sample Output

 

Hint

In the first sample the answer may be achieved this way:

  • Append GCD(1,2,3)=1(1,2,3)=1 , remove 22 .
  • Append GCD(1,3)=1(1,3)=1 , remove 11 .
  • Append GCD(3)=3(3)=3 , remove 33 .

We get the sequence [1,1,3][1,1,3] as the result.

尽可能的让大的gcd值尽快出现。

有一条规则可以推出来,两个连续的数的gcd是1,所以第一步是将原数列变成奇数数列或偶数数列,又因为对于长度n大于3时,偶数数列肯定要先出现大的gcd,所以第一步将原数列转成偶数数列。

之后有趣的事情就出现了,可以发现,可以将形成的数列,奇数位上的数看“奇数数列”,偶数位上的数看成“偶数数列”,又重复第一步的过程。

在以上整个程中n都是大于3的,对于小于3的直接按“偶奇奇”的顺序删。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; int con[]; int gcd(int a,int b)
{
int c;
while(b)
{
c=b;
b=a%b;
a=c;
}
return a;
} int main()
{
int i,p,j,n;
int cnt=;
scanf("%d",&n);
for(i=;i<=n;i++)
con[i]=i;
p=n;
while(p>)
{
if(p==)
{
printf("%d %d %d\n",gcd(gcd(con[],con[]),con[]),gcd(con[],con[]),con[]);
break;
}
else if(p>=)
{
cnt=;
int k=gcd(con[],con[]);
for(i=;i<=p;i+=)
{
printf("%d ",k);
if(i+<=p)
con[++cnt]=con[i+];
}
p=cnt;
}
else if(p==)
{
printf("%d\n",con[p]);
break;
} }
return ;
}

CodeForces 1059C的更多相关文章

  1. [CodeForces]1059C Sequence Transformation

    构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...

  2. CodeForces - 1059C Sequence Transformation (GCD相关)

    Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...

  3. codeforces 1059C. Sequence Transformation【构造】

    题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 微软职位内部推荐-Senior Software Development Engineer_Commerce

    微软近期Open的职位: Are you looking for a high impact project that involves processing of billions of dolla ...

  2. 了不起的Node.js--之一

    在OSX下安装Nodejs 从Node.js官网下载PKG文件,其文件名格式遵循node-v.?.?.?.pkg.若要通过手动编译来进行安装,请确保机器上已安装了XCode,然后根据Linux下的编译 ...

  3. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  4. 关于断言(Assert)

    断言,字面上的意思大致是十分肯定的说,也就是说我们相信这个结果是真的.如果我们的断言不为真,那这个这个结果就和我们预期的结果不一样.在编程上同理,如果程序运行出来的结果和你想要的结果不一致,那你的程序 ...

  5. 英语学习/词典App分析-团队作业(五)

    英语学习/词典APP排行五排名: 1.网易有道词典(单词查询翻译类软件). 2.百词斩(单词记忆类软件). 3.沪江开心词场. 4.金山词霸. 5.流利说英语(英语口语APP). 个软件的分析: 1. ...

  6. 使用Arduino驱动基于ST7533芯片的TFT屏

    在合宙通信买了一个1.8寸的TFT屏,驱动芯片是ST7533,本来打算使用Air800直接驱动,但由于其他原因,放弃了.于是尝试使用arduino驱动,为了屏幕刷新速度更快,采用硬件SPI. 硬件连接 ...

  7. 【Leetcode】209. Minimum Size Subarray Sum

    Question: Given an array of n positive integers and a positive integer s, find the minimal length of ...

  8. CMS垃圾收集器与G1收集器

    1.CMS收集器 CMS收集器是一种以获取最短回收停顿时间为目标的收集器.基于“标记-清除”算法实现,它的运作过程如下: 1)初始标记 2)并发标记 3)重新标记 4)并发清除 初始标记.从新标记这两 ...

  9. 顺序表的C、C++实现

    一个线性表表实现,函数声明放在 line_list.h 头文件汇总,函数定义放在line_list.c 中,main.c 用来测试各个函数. 1.文件 line_list.h // line_list ...

  10. 默认css修改

    input-------------------------------------------------- .input-item input{ width: 100%; height: 60px ...