Consider a directed graph whose vertices are numbered from 1 to n. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3i. The task is to find the minimum number of edges in a path in G from vertex 1 to vertex n.
Input:
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case contains a value of n.
Output:
Print the number of edges in the shortest path from 1 to n.
Constraints:
1<=T<=30
1<=n <=1000
Example:
Input:
2
9
4
Output:
2
2
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.
bruceewayne | 192 |
manvirag982 | 178 |
theAwesome | 168 |
shivam123ahuja | 167 |
Core_Ka_Bachha | 160 |
mr_kksparrow | 433 |
manvirag982 | 394 |
TheHandle | 282 |
rajupraaa1234 | 276 |
Exception_404 | 268 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |