Equal Operation

3.2

5 votes
, Math, Algorithms, Linear Search
Problem

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

  • Choose an index i(1i≤∣A), split Ai into two positive integers X,Y such that Ai=X+Y, remove the ith 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 A1,A2,,AN - 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

1T1041N1051Ai109SumofNoveralltestcasesdoesnotexceed2105.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Test case 1: Choose i = 2 and split A[2] = 4 into X = 2, Y = 2 making A = [2, ,2, 2]. Now all elements of the array are equal. 

Test case 2: 

  • Choose i = 2 and split A[2] = 2 into X = 1, Y = 1 making A = [1, 3, 1, 1]. 
  • Choose i = 2 and split A[2] = 3 into X = 2, Y = 1 making A = [1, 1, 1, 2, 1]. 
  • Choose i = 4 and split A[4] = 2 into X = 1, Y = 1 making A = [1, 1, 1, 1, 1, 1]. Now all elements of the array are equal. 
Editor Image

?