1. 程式人生 > >Sequence Transformation(CodeForces 1059C)

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;
}