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. Linux内核分析:完成一个简单的时间片轮转多道程序内核代码

    PS.贺邦   原创作品转载请注明出处  <Linux内核分析>MOOC课程    http://mooc.study.163.com/course/USTC-1000029000 1.m ...

  2. YQCB冲刺第二周第四天

    站立会议 任务看板 今天的任务为实现精准查账的功能. 昨天的任务为实现查看消费明细的功能. 遇到的问题为忘记在记账记录的表中添加用户名一栏,这样导致不同用户登录时查看消费明细会显示所有用户的所有记录.

  3. UART协议总结

    之前一直使用UART作为单片机之间以及和计算机的简单通信,但一直没有研究过该协议的内部原理.今天刚买了一个逻辑分析仪,于是使用该分析仪对UART数据进行分析,以便更好的理解UART协议原理. UART ...

  4. spring动态数据源+事务

    今天在尝试配置spring的动态数据源和事务管理的时候,遇到了几处配置上的问题,在此记录下: 1.使用了spring的aop思想,实现了动态数据源的切换. 2.spring的事务管理,是基于数据源的, ...

  5. 使用navicat 链接数据库时乱码

    在建立数据库链接时设置  高级->编码->uft-8 其他版本使用下面方法

  6. 远程显示(操作) 服务器 GUI 程序(图形化界面) (基于 X11 Forwarding + Centos + MobaXterm)

    在做 数据分析(数据挖掘 或 机器学习)的时候,我们经常需要绘制一些统计相关的图表,这些统计.绘图的程序常常是跑在服务器上的,可是服务器出于性能和效率的考虑,通常都是没有安装图形化界面的,于是这些统计 ...

  7. Java之File类详解

    常用操作: File f = new File("C:\\testdata\\filedir\\a\\b\\c"); f.mkdir(); //建立单级目录 f.mkdirs(); ...

  8. anaconda的spyder打不开

    因为最近一段时间没有用Spyder,今天使用时,发现Spyder又又打不开了. 之前遇到Spyder打不开的情况时,是根据这里的教程:删除.matplotlib和.spyder两个文件,但这次删除这两 ...

  9. sql bak还原到新数据库

    1 创建新数据库  TestDB 2  使用语句 use master restore database [TestDB] from disk = 'D:\SqlDataBak\SanJu\SanJu ...

  10. MySQL5.7 的编译安装

    转: 5.7的安装: https://www.insp.top/article/make-install-mysql-5-7 5.6的安装: https://www.chenyudong.com/ar ...