CF BUDDY
← Problems·

1059C · Sequence Transformation

1600 · constructive algorithms, math

Problem: 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, \dots, n. Find the lexicographically maximum result of its transformation.

A sequence a1,a2,,ana_1, a_2, \ldots, a_n is lexicographically larger than a sequence b1,b2,,bnb_1, b_2, \ldots, b_n, if there is an index ii such that aj=bja_j = b_j for all j<ij < i, and ai>bia_i > b_i.

Input Format: The first and only line of input contains one integer nn (1n1061\le n\le 10^6).

Output Format: Output nn integers  — the lexicographically maximum result of the transformation.

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.

Sample Cases

Case 1

Input

3

Output

1 1 3

Case 2

Input

2

Output

1 2

Case 3

Input

1

Output

1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback