Given an array arr[] of size N, the task is to find the minimum number of operations to reduce the array by deleting an element and all its multiples from the array in one operation.
Examples:
Input: N = 5, arr[] = {5, 2, 3, 8, 7}
Output: 4
Explanation: Removing 2, will make it remove 8 (as it is a multiple of 2),
then 3, 5, 7 would be removed in one operation each,
Thus, total count = 1 + 3 = 4 (Required Answer)Input: N = 7, arr[] = {12, 10, 2, 3, 5, 6, 27}
Output: 3
Explanation: Removing 2 and its multiples 10, 12, 6 in one operation. So count = 1.
Then, remove 3 and 27 (multiple of 3) in one operatino. So total count = 1+1 = 2.
Last element left would be 5 which will again take one operation.
Thus, total count = 2 + 1 = 3 (Required Answer)
Approach: The approach to the solution is based on the following idea:
Sort the array and then start iterating from the start.
For each element group all its multiples together if it already is not part of any group.
The total number of group is the required answer.
Follow the steps to solve the problem:
 Sort the array in increasing order.
 Iterate from the i = 0 to N1 and:
 If this element is part of any group or not.
 If not then group this element and all its multiples together.
 Otherwise, skip this and continue iteration.
 Return the count of the total number of groups.
Below is the implementation of the above approach:
C++

Time Complexity: O(N*M) where M is the maximum element of the array
Auxiliary Space: O(M)