#C9898. Custom Sorting of Index Cards
Custom Sorting of Index Cards
Custom Sorting of Index Cards
You are given a set of index cards with integers written on them. Your task is to sort these cards using a custom sorting algorithm. Specifically, for each integer ( x ), compute its number of distinct divisors, denoted as ( d(x) ). The sorting rule is as follows:
- Cards with a smaller number of divisors come first.
- If two cards have the same number of divisors, the card with the smaller integer comes first.
The number of distinct divisors ( d(x) ) is defined as: [ d(x) = |{ i \mid 1 \le i \le x,; x \bmod i = 0 }|. ]
For example:
- For ( x = 6 ), its divisors are ( {1,2,3,6} ), so ( d(6)=4 ).
- For ( x = 5 ), its divisors are ( {1,5} ), so ( d(5)=2 ).
Given the number of cards and their values, output the sorted list of integers in one line, separated by a space.
Note: The input is given via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains an integer ( n ) ((1 \le n \le 10^5)) representing the number of index cards.
- The second line contains ( n ) space-separated integers, where each integer represents the value on an index card.
outputFormat
Print the sorted list of integers in a single line. The numbers should be separated by spaces.## sample
5
2 3 4 6 5
2 3 5 4 6