[Solution] Luigi and Uniformity CodeChef Solution
Problem
Luigi has an array of positive integers. He wants to make all elements of the array equal.
In one move, he can:
- Choose an index and divide the element by any one of its divisors.
In other words, he can choose a positive integer such that and set .
Find the minimum number of moves required to make all the elements of the array equal.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains , the size of array .
- The second line of each test case contains space-separated integers, the elements of array .
Output Format
For each test case, output on a new line, the minimum number of moves required to make all elements of the array equal.
Explanation:
Test case : We can change to using an operation (divide by ). Thus, using one operation, we made all the elements equal.
Test case : All numbers are already same. Thus, we do not need to do any operations.
Test case : We make the following operations:
- Choose and , such that . Thus, .
- Choose and , such that . Thus, .
Thus, using two operations, we made all the elements equal.
Test case : We make the following operations:
- Choose and , such that . Thus, .
- Choose and , such that . Thus, .
- Choose and , such that . Thus, .
- Choose and , such that . Thus, .
Thus, using four operations, we made all the elements equal.
No comments:
Post a Comment