BETA

Difficulty Level:

Easy

Total Submissions: 550 Accuracy:

36.73%

Minimum steps to minimize n as per given condition
     

Given a number n, count minimum steps to minimise it to 1 according to the following criteria:

  • If n is divisible by 2 then we may reduce n to n/2.
  • If n is divisible by 3 then you may reduce n to n/3.
  • Decrement n by 1.

 

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the number n.

 

Output:

Output the minimum steps to minimise the number in a new line for each test case.


Constraints:

1<= T <=1000

1<= N <=10000


Example:

Input:

2

10

6

Output:

3

2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.