Beautiful Sequence
Submissions: 253   Accuracy:

29.23%

  Difficulty: Easy   Marks: 2

We have Infinitely Many Choclates and infinitely many children . And, We want to give them to children, But we will not give More than 'N' choclates to any one child. And, we want to give 'N' choclates to exactly 1 child.
And, We want to give the
choclates to as many children possible, in a beautiful sequence only.
A beautiful sequence is an increasing sequence, in which a term Ai divides all Aj, where j>i.
For
example: 3, 6, 24 is a beautiful sequence of length 3.

  • 3 divides 6 and 24
  • 6 divides 24

We would give

  • A0 choclates to the first child,
  • A1 choclates to the second child
  • ...and so on
    We want maximum Children to get the
    choclates. Output the Beautiful Sequence of maximum length.
     

 

Input
The first line contains T, the total number ofTestcases. Then Each of the next T lines, contains an integer denoting -'N'.

Output
For each testcase
, Print the beautiful sequence of maximum length.

Constraints

  • 1T ≤ 1000
  • 1N ≤ 1000000

Example
Input: 4
10
4
24
3

Output:
1 5 10
1 2 4
1 3 6 12 24
1 3

Explanation
In the first case,N=10, 1 divides 5 and 10 5 divides 10. We can't give more than 10 choclates to any child, So We have to stop And this is the max. length achievable i.e.3.
Note that 1 2 10 is also a beautiful sequence of length 3, but we will choose that sequence containing more no. of choclates.i,e. 1 5 10

In the Second case,N=4, 1 divides 2 and 4 2 divides 4 .We can't give more than 4 choclates to any child, So we has to stop And this is the max. length achievable i.e.3

In the Third case,N=24 1 divides 3,6,12 and 24 3 divides 6,12, and 24. 6 divides 12 and 24 12 divides 24 We can't give more than 24 choclates to any child, So We have to stop and this is the max. length achievable i.e.5

In the Fourth Case , N=3  1 divides 3 . So We have to stop And this is the max. length achievable i.e. 2choclates, 3 is divisible by 1.  

** For More Input/Output Examples Use 'Expected Output' option **

Author: iamabjain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.