C. Sequence Transformation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 (1≤n≤1061≤n≤106).
Output
Output nn 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(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.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int flag = 1;
while(n > 3){
for(int i = 1; i <= ((n + 1) >> 1); i++) cout << flag << " ";
n >>= 1, flag <<= 1;
}
if(n == 3) printf("%d %d %d\n", flag, flag, flag * 3);
if(n == 2) printf("%d %d\n", flag, flag * 2);
if(n == 1) printf("%d\n", flag);
return 0;
}