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.

Examples

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

Note

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.

题目大意:

每次从1..n中删去一个数,求剩余数GCD的可能最大字典序序列。

当n>=4时,所有数中有2这个质因子的一定占多数,所以将不含2质因子的数删除,再将剩下的数除以二,又转化成1..n/2的输出问题。(详见代码)

这题是练习的时候自主想出的,纪念下。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack> typedef long long lol; using namespace std; const int maxn=; int main()
{
int n;
scanf("%d",&n);
for(int i=;;)
{
if(n==)
{
printf("%d\n",*i);
break;
}
else if(n==)
{
printf("%d %d\n",*i,*i);
break;
} else if(n==)
{
printf("%d %d %d\n",*i,*i,*i);
break;
}
else
{
for(int j=;j<=(n+)/;j++)
printf("%d ",*i);
n/=;
i*=;
}
}
return ;
}

CodeForces - 1059C Sequence Transformation (GCD相关)的更多相关文章

  1. [CodeForces]1059C Sequence Transformation

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

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

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

  3. Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)

    C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操 ...

  4. 【CF 1059C】 Sequence Transformation 数学

    C. Sequence Transformation:http://codeforces.com/contest/1059/problem/C 题意 给你一个n,第一次输出1-n个数的gcd,然后你可 ...

  5. CF1059C Sequence Transformation 题解

    这几天不知道写点什么,状态也不太好,搬个题上来吧 题意:给定一个数n,设一个从1到n的序列,每次删掉一个序列中的数,求按字典序最大化的GCD序列 做法:按2的倍数找,但是如果除2能得到3的这种情况要特 ...

  6. Codeforces 486C Palindrome Transformation(贪心)

    题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...

  7. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  8. codeforces 894C - Marco and GCD Sequence - [有关gcd数学题]

    题目链接:https://cn.vjudge.net/problem/CodeForces-894C In a dream Marco met an elderly man with a pair o ...

  9. Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造

    题意 给出一个1-n的集合   gcd 集合里面的所有数  得到的 一个 数   然后自己选择删去一个数   要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数 ...

随机推荐

  1. Excel的常用函数

    1.查找重复内容=IF(COUNTIF(A:A,A2)>1,"重复","") 2.重复内容首次出现时不提示=IF(COUNTIF(A$2:A2,A2)&g ...

  2. 24 道 shell 脚本面试题

    想要成为中高级phper, shell 脚本是需要掌握的,它有助于你在工作环境中自动完成很多任务. 如下是一些面试过程中,经常会遇到的 shell 脚本面试问题及解答: Q:1 Shell脚本是什么. ...

  3. 如何在maven中下载jar包

    1.进入maven网址  https://mvnrepository.com/ 2.搜索你想要的包的名字 3.找到列表中你想要的包 4.点击一个版本 5.点击 view all 6.找到你想要的包,点 ...

  4. add jar and proxy repo

    1. 添加代理仓库 2. 添加host 仓库 3. 添加私有jar 4. 添加仓库到public 仓库

  5. Nvm安装步骤

    下载地址 https://github.com/coreybutler/nvm-windows/releases 解压压缩包,后是一个.exe结尾的安装文件,双击安装, 选择安装位置,如下图: 设置n ...

  6. PostGIS 查询点在线上

    1.缓冲区法:查询数据库fm表里,与坐标(12989691.512 4798962.444)相距0.0001米的数据(3857坐标系) ),),),),geom) ; --如果坐标系统一,不用tran ...

  7. jQuery学习笔记3

    * 动画效果 * 在一定的时间内, 不断改变元素样式 * slideDown()/slideUp()/slideToggle() * fadeOut()/fadeIn()/fadeToggle() * ...

  8. C#面向对象--命名空间

    一.在C#中,使用命名空间(Namespace)可以帮助控制自定义类型的作用范围,同时对大量的类型进行组织:使用namespace关键字声明命名空间,命名空间可以嵌套使用: namespace MyN ...

  9. idea为什么maven工具栏下面没有dependencies跟Plugins

    刚刚新建的springboot项目,然后进来就是这样子 网上查找资料有些说是maven版本的问题,但是对于我的问题并没有得到解决. 现在是2019年12月4日16:23:07,依然没有找到解决方法,不 ...

  10. easywechat微信开发SDK之小微商户进件(一)

    微信本身不提供小微商户进件的SDK,偶然发现easywechat这么个东西,官网地址是https://www.easywechat.com/  整合了微信开发中常用的接口,包括微信公众号相关接口,微信 ...