Minimum steps to minimize n as per given condition
Submissions: 4107   Accuracy:

36.53%

  Difficulty: Easy   Marks: 2

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
Author: sujnesh


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



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


to report an issue on this page.