#Lutece1665. Sharkovski’s Ordering
Sharkovski’s Ordering
Migrated from Lutece 1665 Sharkovski’s Ordering
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
In a paper on continuous mappings of the reals into the reals, used the following ordering of the positive integers:
◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄ ◄
As and describe it:
“First come the odd numbers, beginning with , arranged in increasing order. This sequence is repeated with each odd integer multiplied by . The initial sequence is again repeated with each odd integer multiplied by , and so on. The terminal sequence consists of the nonnegative powers of arranged in decreasing order (note that ).”
Write a program that reads an input containing a list of up to unsigned integers with values less than or equal to (not necessarily distinct) separated by white space and terminated by ‘’. The program should display on the screen the numbers arranged in Sharkovski’s ordering in one line. The numbers in the line are separated exactly by one space.
Input
The input starts with an integer . This is followed by input cases. Each input case is a non-empty list of up to unsigned integers (not necessarily distinct) with values not exceeding . Each pair of numbers is separated by white space. Each input case is terminated by ‘’.
Output
For every input case, print the required numbers arranged in Sharkovski’s ordering in one line. The numbers in the line are separated exactly by one space.
Samples
2
3 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 0
3
3 5 7 9 11 13 15 17 19 6 10 14 18 12 16 8 4 2 1 1
Resources
Philippines > Philippines Multi-Provincial Programming Contest 2013 Problem F