Luigi and Uniformity Codechef solutions Today | Codechef Starters 64✅ (100/100) FULL | AC Code ✅| DIVIDEMAKEEQ
IF ANYONE DONE THIS AND IS YOU WANT TO HELP SO JUST WRITE DOWN CODE IN COMMENTS
For Solution
“Coming Soon After 10 Minutes“
int t;
cin>t;
while(t--){
cin>>n;
for(i=0;i<n;i++) cin>>a[i];
x=a[0];
for(i=1;i<n;i++){
x=gcd(x,a[i]);
}
cnt=0;
for(i=0;i<n;i++){
if(a[i]==x) cnt++;
}
cout<<n-cnt<<endl;
}
}
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.
Constraints
Sample 1:
4 2 11 22 5 38 38 38 38 38 4 4 4 16 8 4 11 13 17 19
1 0 2 4
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.