Sequence Transformation(CodeForces 1059C)

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,…,n. Find the lexicographically maximum result of its transformation.

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

Input

The first and only line of input contains one integer nn (1≤n≤10^6).

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 

Hint

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

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

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

题解:一开始的gcd肯定是1,要让字典序最大,我们可以想到下一个应该是2。这样就要把所有的奇数全给删去,这样就要考虑一个特殊情况,就是把所有奇数删去之后,刚好n==1的时候。因为n==1的话,gcd就是剩下的那个数本身了。因此要特判n==3的情况。(不少人认为最后一个数为n,如果为奇数,一定不成立。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;


int main()
{
    int n;
    cin>>n;
    int k=1;
    while(n)
    {
        if(n==3)
        {
            cout<<k<<" "<<k<<" "<<k*3<<endl;
            return 0;
        }
        for(int i=0; i<(n+1)/2; i++)
            cout<<k<<" ";
        n/=2;
        k*=2;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值