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. kubeadm安装kubernetes 1.13.1集群完整部署记录

    k8s是什么 Kubernetes简称为k8s,它是 Google 开源的容器集群管理系统.在 Docker 技术的基础上,为容器化的应用提供部署运行.资源调度.服务发现和动态伸缩等一系列完整功能,提 ...

  2. 初始化Weex项目遇到的问题记录

    Weex 提供了一个命令行工具 weex-toolkit 来帮助开发者使用 Weex.它可以用来快速创建一个空项目.初始化 iOS 和 Android 开发环境.调试.安装插件等操作. 目前 weex ...

  3. HAOI2017 新型城市化 二分图的最大独立集+最大流+强连通缩点

    题目链接(洛谷):https://www.luogu.org/problemnew/show/P3731 题意概述:给出一张二分图,询问删掉哪些边之后可以使这张二分图的最大独立集变大.N<=10 ...

  4. 从C简单程序的汇编代码入手,以理解计算机工作原理。

    贺邦  原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000#/info 知识准备 ...

  5. 《TCP-IP详解卷1》中BGP部分的笔记

  6. Git(2.14.1版本)学习及使用(一)

    OuZeBo原创作品.转载请注明出处 http://www.cnblogs.com/OuZeBo/p/7477465.html 1.下载git:https://git-scm.com/ 2.安装(本人 ...

  7. “数学口袋精灵”第二个Sprint计划---第一天

    “数学口袋精灵”第二个Sprint计划----第一天进度 任务分配: 冯美欣:欢迎界面的音效 吴舒婷:游戏界面的动作条,选择答案后的音效 林欢雯:完善算法代码的设计 进度:   冯美欣:上网百度音乐资 ...

  8. Docker(十一)-Docker commit创建镜像

    创建镜像有很多方法,用户可以从 Docker Hub 获取已有镜像并更新,也可以利用本地文件系统创建一个. 修改已有的镜像 查看已有的镜像: $ sudo docker images REPOSITO ...

  9. Yii框架的原代码

    http://www.digpage.com/app_struct.html#index-php

  10. apache 运行一段时间出现错误

    环境是win2008,apache 2.4.29 Win64 VC15,php 7.1.10(7.1.11).事件完整内容: “-------------------------- 错误应用程序名称: ...