Equal Operation
Practice
3.2 (5 votes)
Math
Algorithms
Linear search
Problem
40% Success 1622 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) containing \(N\) integers. You can apply the following operation on the array:

  • Choose an index \(i \;(1 \le i \le \mid A\mid)\), split \(A_i\) into two positive integers \(X, Y\) such that \(A_i = X+Y\), remove the \(i^{th}\) element from the array and append the elements \(X, Y\) to the array.

Find the minimum number of operations required to make all integers of the array equal.

 Input format

  • The first line contains \(T\) denoting the number of test cases. The description of \(T\) test cases is as follows:
  • For each test case:
    • The first line contains a single integer \(N\) denoting the size of array \(A\).
    • The second line contains \(N\) integers \(A_1, A_2, \dots, A_N\) - denoting the elements of \(A\).

Output format
For each test case, print the minimum number of operations required to make all integers of the array equal.

Constraints

\(1 \leq T \leq 10^4 \\ 1 \leq N \leq 10^5\\ \\1\leq A_i \le 10^9 \\ Sum\; of \; N\;over\;all\;test\;cases\;does\;not\;exceed\;2\cdot 10^5. \)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
107 votes
Tags:
Number TheoryData StructuresEasy-MediumGreedy algorithmReadyApproved
Points:20
97 votes
Tags:
AlgorithmsEasySearching
Points:20
14 votes
Tags:
Linear SearchAlgorithmsGreedy algorithm