Cycle Prefix Averages
Difficulty: Easy
Question
Prefix Averages Algorithm is used to calculate average of the first i elements in an array. That algorithm is widely used in financial analysis. Peter, which is a financial analyst, is now wondering if he keeps repeating the prefix averages, how many times it repeats until all the numbers are same as first element. To make things simple, he will omit any trailing decimals during finding the averages instead.
Input Format
The first line consists of an integer N, which is the number of arrays to input. Starting from second line, there 1D array which consist of various numbers with various size, given all integers.
Constraints
Output Format
Output the total count of cycle per line, which makes all numbers in an array into 1. If it is impossible to make all numbers in an array into 1, print -1 instead.
Sample Inputs:
Input
4
11 23 5 27 33 1 45 18
101325 999999 8763 1599 20
2 3 5 7 11 13 17 19 23 29
12333 33455 101325 114514 1919810
Output
5
22
4
16
Explanation
Taking first line as example:
In first cycle:
[0]: 11
[1]:
[2]:
...
[7]:
The new array becomes:
Repeat the cycle again until the array becomes:
And it took 5 cycles to complete it.
Last updated