Strange Beauty
Practice this coding question on Coding Gurukul.
Problem statement
A curator arranges mechanical gears into compatible display sets. Two gears are compatible when the tooth count of one divides the tooth count of the other. A display is approved only if every pair of retained gears is compatible, and the curator wants to remove as few gears as possible. Your task For each array of positive tooth counts, find the minimum number of elements to remove so that for every pair of remaining indices, one value divides the other. Important details Equal values are compatible and represent separate gears that may all remain. Compatibility must hold for every pair, not only neighboring elements in the input. You may remove any positions; the original order does not restrict the chosen set. A single gear always forms a valid display. Worked example For 2 3 6 12, retain 2 6 12 and remove 3, giving answer 1. Retaining 3 6 12 is equally good. Keeping all four is invalid because neither 2 nor 3 divides the other. For 2 2 8, all three gears can remain.
Input format
Read t. For each case read n, then n positive integers.
Output format
Print the minimum removals for each case.
Constraints
1 <= t <= 10; 1 <= n <= 1000; total n <= 1000; 1 <= value[i] <= 200000.
Sample input
1 4 2 3 6 12
Sample output
1
Sign in to run or submit a solution in C++, Java or Python.