You are given a set of positive integers. You must arrange them into pairs such that:
- Each pair contains 2 numbers, one of which is a multiple of another. For example, 8 is a multiple of 4, and 9 is a multiple of 9.
- If the same number occurs many times in the initial set, it can be used that many times in the pairs; a number can even be paired with another occurence of the same number
- The maximum possible number of pairs is obtained.
Output must be the number of pairs. Shortest code wins.
Sample data
2,3,4,8,9,18
-> 3
7,14,28,42,56
-> 2
7,1,9,9,4,9,9,1,3,9,8,5
-> 6
8,88,888,8888,88888,888888
-> 3
2,6,7,17,16,35,15,9,83,7
-> 2
2,3,4,8,9,18
. (Each number in that list is a factor and/or multiple of at least two other numbers in the list, but it has only one solution.) \$\endgroup\$