Question
Divisor Sort Bibi has always been fascinated by numbers. Currently, she is researching the correlation between a number and the sum of its divisors. A
Divisor Sort
Bibi has always been fascinated by numbers. Currently, she is researching the correlation between a number and the sum of its divisors. A number K is a divisor of X if K
fully divides X and leaves no remainder. The number 6 for example, has a sum of 12
which comes from 1 + 2 + 3 + 6. To speed up her research, she has asked your help as
her programmer friend to help create a program that can sort an array of numbers A
ascendingly based on the sum of its divisors. In case of a tie, she has asked you to output
the smaller number before the larger number.
Format Input
A single line with an integer N denoting the number of elements followed by another line
containing N elements denoting the numbers in the array.
Format Output
A single line with N elements separated by a single space denoting the sorted array
satisfying Bibis requirements.
Constraints
1 N 10^3
1 Ai 10^4
Each element in A does not appear more than once
Sample Input 1
5
1 13 6 7 2
Sample Output 1
1 2 7 6 13
Sample Input 2
10
1 2 3 4 5 6 7 8 9 10
Sample Output 2
1 2 3 5 4 7 6 9 8 10
Note : Use C Language , Dont Use Stdlib as you can
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started