

1. Reset the counter with the number of balls present in the box.
2. Press the throw button.
The first line contains 'T', denoting the number of tests.
For each Test :
The only line contains one integer 'N', denoting the required number of balls in the box.
For each test, print one integer, denoting the minimum number of operations needed to collect exactly 'N' balls in the box.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= 'T' <= 10^3
1 <= 'N' <= 10^6
Time Limit: 1 sec
Let the resetting operation be denoted by 'R' and throw denoted by 'T'. It can be seen that consecutively performing two or more 'R' operations is just a waste of moves, as the counter remains the same.
So, any optimal order of operations will look like "RTTTRTTRTTTT….", i.e., each 'R' followed by one or more 'T's.
Let's break this order into groups: [RTTT, RTT, RTTTT, …. ], and size of groups be [s1, s2, s3, ….]. Initially, the box contains one ball; after performing the first group of operations, it will contain 's1' balls (1 initial ball + 's1' - 1 throw with counter = 1).
The same is followed for each group of operations; after performing the second group of operations, the box will contain s1 * s2 balls (s1 previous balls + 's2' - 1 throw with counter = s1).
Thus, the total number of balls in the box becomes (s1 * s2 * s3 * ....), and the number of operations becomes (s1 + s2 + s3 + ….).
If any 's' can be denoted as (s = p * q), it must be divided into 'p' and 'q' because the product remains the same, but p+q will be less than or equal to 's'.
We need (s1 * s2 * s3 * ….) to be exactly equal to 'N'. Hence our desired answer is the sum of all prime factors of 'N'.
Algorithm: