Fork me on github

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

 

posted @ 2018-10-17 22:59  acboyty  阅读(127)  评论(0编辑  收藏  举报