Let’s call the following process a transformation of a sequence of length n
.
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 n
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 n
(1≤n≤106
).
Output
Output n
integers — the lexicographically maximum result of the transformation.
Examples
Input
Copy
3
Output
Copy
1 1 3
Input
Copy
2
Output
Copy
1 2
Input
Copy
1
Output
Copy
1
Note
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 ,那么最先可能出现>1 的gcd 也只有2;
----->
也就是说,除去奇数后所剩的偶数中,我们/2后仍按刚才的方法进行筛选;
总复杂度:
O( n*logn );
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-10
typedef pair<int, int> pii;
inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
int qu[maxn];
int ans[maxn];
int n;
int cnt;
void sol(int n, int ml) {
if (n == 1) {
ans[++cnt] = ml; return;
}
if (n == 2) {
ans[++cnt] = ml; ans[++cnt] = ml*2; return;
}
if (n == 3) {
ans[++cnt] = ml; ans[++cnt] = ml; ans[++cnt] = ml * 3;
return;
}
for (int i = 0; i < n; i++) {
if (qu[i] % 2)ans[++cnt] = ml;
}
for (int i = 0; i < n / 2; i++) {
qu[i] = qu[i * 2 + 1] / 2;
}
sol(n / 2, ml * 2);
}
int main()
{
//ios::sync_with_stdio(false);
rdint(n);
for (int i = 0; i < n; i++)qu[i] = i + 1;
sol(n, 1);
for (int i = 1; i <= cnt; i++) {
cout << ans[i] << ' ';
}
cout << endl;
}