Programming contests

50 Programming Exercise for Beginners

January 2, 2019 12:00 AM – December 31, 2019 12:00 AM

Divisors

Write a program that reads positive integers from each line of the standard input until end-of-file (EOF). The first number of each line determines how many additional numbers are given in that line.

For each line, the program should sort the numbers in ascending order of the (positive) number of their divisors. If two or more numbers have the same number of divisors, sort them in ascending order of magnitude.

Write each ordered sequence of numbers in a separate line, separating the elements of a sequence from each other with a single space character.

Sample Input

  1. 10 1 2 3 4 5 6 7 8 9 10
  2. 10 11 12 13 14 15 16 17 18 19 20
download as text file

Output for Sample Input

  1. 1 2 3 5 7 4 9 6 8 10
  2. 11 13 17 19 14 15 16 12 18 20
download as text file

Possible solutions: main1.c and main2.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019