CodeForces - 1059C Sequence Transformation (GCD相关)

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 (1n1061≤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=1000;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;;)
    {
        if(n==1)
        {
            printf("%d\n",1*i);
            break;
        }
        else if(n==2)
        {
            printf("%d %d\n",1*i,2*i);
            break;
        }

        else if(n==3)
        {
             printf("%d %d %d\n",1*i,1*i,3*i);
             break;
        }
        else
        {
            for(int j=1;j<=(n+1)/2;j++)
                printf("%d ",1*i);
            n/=2;
            i*=2;
        }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/acboyty/p/9807752.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值