MST1 - Minimum Step To One

no tags 

Problem statement is very easy. On a positive integer, you can perform any one of the following 3 steps.

  1. Subtract 1 from it. (n = n - 1)
  2. If it is divisible by 2, divide by 2. (if n % 2 == 0, then n = n / 2)
  3. If it is divisible by 3, divide by 3. (if n % 3 == 0, then n = n / 3)

Given a positive integer n and you task is find the minimum number of steps that takes n to one.

Input

The input contains an integer T (1 ≤ T ≤ 100) number of test cases. Second line input is N (0 < N ≤ 2*107) that indicates the positive number.

Output

For each case, print the case number and the minimum number of steps.

Example

Input:
3
1
4
7

Output:
Case 1: 0
Case 2: 2
Case 3: 3

Explanation

  1. For N = 1, output: 0
  2. For N = 4, output: 2 (4 /2 = 2 /2 = 1)
  3. For N = 7, output: 3 ( 7 -1 = 6 /3 = 2 /2 = 1)

hide comments
Shipu Ahamed: 2014-07-20 14:20:29

i don't know ...... is it hackerrank problem ........ ??? link please @785227
and check also hacker rank contest date and my problem submiting date .......

Last edit: 2014-07-24 20:15:17
785227: 2014-06-07 19:15:52

This is a hackerrank problem

Rishabh Roy: 2013-12-08 22:53:45

[code removed -- see below, "1. Don't post any source code here."]

giving segmentation fault plz help

Last edit: 2013-12-09 05:13:06

Added by:Shipu Ahamed
Date:2013-05-11
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64