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. 【SE】Week3 : 个人博客作业(必应词典)

    关于 微软必应词典客户端 的案例分析 [第一部分]  调研,评测 一.用户采访 1)   介绍采访对象的背景和需求: 被采访同学是马来西亚华裔叶能端同学,由于此前在马来西亚英语是第二语言,因此经常需要 ...

  2. 2-Nineteenth Scrum Meeting-20151219

    任务安排 成员 今日完成 明日任务 闫昊 写完学习进度记录的数据库操作 请假(数据库) 唐彬 和服务器老师交流讨论区后台接口 请假(数据库) 史烨轩  尝试使用downloadmanager对noti ...

  3. Visual Studio 2015的安装和简单的测试

    首先是Visual Studio 2015的安装 Visual Studio是微软开发的一套基于组件的软件开发工具,目前最新的版本是2015. 在 I Tell you 网站下载Visual Stud ...

  4. ElasticSearch 2 (32) - 信息聚合系列之范围限定

    ElasticSearch 2 (32) - 信息聚合系列之范围限定 摘要 到目前为止我们看到的所有聚合的例子都省略了搜索请求,完整的请求就是聚合本身. 聚合与搜索请求同时执行,但是我们需要理解一个新 ...

  5. C#简述(三)

    详细请参考:http://www.runoob.com/csharp/csharp-string.html 1.C# 字符串(String) 在 C# 中,可以使用字符数组来表示字符串,但是,更常见的 ...

  6. JS面向对象编程:对象

    一般面向过程的写法都是写很多function,坏处:1.代码复用不好 2.函数名称容易重复冲突 下面介绍面向对象的写法: 在JS中每个函数function都是一个对象. 比如,下面这个就是一个对象,我 ...

  7. Linux 下安装nginx的总结 (之前写的有问题))

    1. 下载niginx的 tar包 下载路径 http://nginx.org/en/download.html 也可以直接使用命令下载 wget http://nginx.org/download/ ...

  8. BZOJ4559 JLOI2016成绩比较(容斥原理+组合数学+斯特林数)

    容斥一发改为计算至少碾压k人的情况数量,这样对于每门课就可以分开考虑再相乘了.剩下的问题是给出某人的排名和分数的值域,求方案数.枚举出现了几种不同的分数,再枚举被给出的人的分数排第几,算一个类似斯特林 ...

  9. BZOJ2729 HNOI2012排队(组合数学+高精度)

    组合入门题.高精度入门题. #include<iostream> #include<cstdio> #include<cstdlib> #include<cs ...

  10. HTTTP及TCP的超时以及KEEP-ALIVE机制小结

    一.HTTP的超时和Keep Alive HTTP Keepalive 机制是http 1.1中增加的一个功能. 在HTTP 1.0中,客户端每发起一个http 请求,等收到接收方的应答之后就断开TC ...