Scube loves Biryani .Shop of Biryani is situated at position 1 (on X-axis) and Scube is standing at position P (on X-axis).In one step Scube can do the following things-.
Let assume currently he is standing at position M
1. He can reach to the position M+1 in one step.
2. He can reach to the position M-1 in one step.
3. If M is divisible by 3 the he can reach to the position M/3 in one step.
Find how many minimum operations is required for Scube to reach the Biryani Shop
The first line contains a single integer P (Initial position of Scube on x-axis).
Print the answer on the first line.
- 1 ≤ P ≤ 1000000000
Input: 4 Output: 2
Input: 8 Output: 3
Example case 1. Initially Scube is standing a position 4 in first operation he we go to 3 now 3 is devisible bye 3 so in second step he can directly reach to 1 as 3/3=1
Example case 2. Initially Scube is standing a position 8 in first operation he will go to 9 now 9 is devisible bye 3 so in second step he can directly reach to 3 as 3/3=3 again in third step he can directly reach to position 1 as 3/3=1
|Time Limit:||- 1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, GO, NODEJS, HASK, D, PERL, FORT, ADA, CAML, ICK, BF, ASM, CLPS, ICON, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, JS, ERL, kotlin, PERL6, CLOJ, COB, FS|
Fetching successful submissions